From 4816925a3d4f744051bbf85dd7f80a237093e390 Mon Sep 17 00:00:00 2001 From: tanyar09 Date: Fri, 17 Oct 2025 14:10:00 -0400 Subject: [PATCH] refactor: Update face processing methods to accept optional limits for photo processing This commit modifies the `process_faces` method in both the `PhotoTagger` and `FaceProcessor` classes to accept an optional `limit` parameter. If `None`, all unprocessed photos will be processed, enhancing flexibility in face processing. Additionally, the `get_unprocessed_photos` method in `DatabaseManager` is updated to handle the optional limit, ensuring consistent behavior across the application. Docstrings have been updated to reflect these changes, improving code documentation and clarity. --- src/core/database.py | 30 +++++++++++++++++++++--------- src/core/face_processing.py | 5 ++++- src/photo_tagger.py | 8 ++++++-- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/core/database.py b/src/core/database.py index 1a344d4..5dfe2d7 100644 --- a/src/core/database.py +++ b/src/core/database.py @@ -354,17 +354,29 @@ class DatabaseManager: ''', (limit,)) return cursor.fetchall() - def get_unprocessed_photos(self, limit: int = 50) -> List[Tuple]: - """Get unprocessed photos""" + def get_unprocessed_photos(self, limit: Optional[int] = None) -> List[Tuple]: + """Get unprocessed photos + + Args: + limit: Maximum number of photos to return. If None, return all unprocessed photos. + """ with self.get_db_connection() as conn: cursor = conn.cursor() - cursor.execute(''' - SELECT id, path, filename, date_taken - FROM photos - WHERE processed = 0 - ORDER BY date_added ASC - LIMIT ? - ''', (limit,)) + if limit is None: + cursor.execute(''' + SELECT id, path, filename, date_taken + FROM photos + WHERE processed = 0 + ORDER BY date_added ASC + ''') + else: + cursor.execute(''' + SELECT id, path, filename, date_taken + FROM photos + WHERE processed = 0 + ORDER BY date_added ASC + LIMIT ? + ''', (limit,)) return cursor.fetchall() def get_unidentified_faces(self, limit: int = 20) -> List[Tuple]: diff --git a/src/core/face_processing.py b/src/core/face_processing.py index 3e70bfc..4f98a9e 100644 --- a/src/core/face_processing.py +++ b/src/core/face_processing.py @@ -92,11 +92,14 @@ class FaceProcessor: # Clear caches self._clear_caches() - def process_faces(self, limit: int = 50, model: str = DEFAULT_FACE_DETECTION_MODEL, progress_callback=None, stop_event=None) -> int: + def process_faces(self, limit: Optional[int] = None, model: str = DEFAULT_FACE_DETECTION_MODEL, progress_callback=None, stop_event=None) -> int: """Process unprocessed photos for faces If provided, progress_callback will be called as progress_callback(index, total, filename) where index is 1-based count of processed photos so far. + + Args: + limit: Maximum number of photos to process. If None, process all unprocessed photos. """ unprocessed = self.db.get_unprocessed_photos(limit) diff --git a/src/photo_tagger.py b/src/photo_tagger.py index a42770a..de7ff36 100644 --- a/src/photo_tagger.py +++ b/src/photo_tagger.py @@ -84,8 +84,12 @@ class PhotoTagger: return self.photo_manager.extract_photo_date(photo_path) # Face processing methods (delegated) - def process_faces(self, limit: int = DEFAULT_PROCESSING_LIMIT, model: str = DEFAULT_FACE_DETECTION_MODEL, progress_callback=None, stop_event=None) -> int: - """Process unprocessed photos for faces with optional progress and cancellation""" + def process_faces(self, limit: Optional[int] = None, model: str = DEFAULT_FACE_DETECTION_MODEL, progress_callback=None, stop_event=None) -> int: + """Process unprocessed photos for faces with optional progress and cancellation + + Args: + limit: Maximum number of photos to process. If None, process all unprocessed photos. + """ return self.face_processor.process_faces(limit, model, progress_callback, stop_event) def _extract_face_crop(self, photo_path: str, location: dict, face_id: int) -> str: