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.
This commit is contained in:
tanyar09 2025-10-17 14:10:00 -04:00
parent 5db41b63ef
commit 4816925a3d
3 changed files with 31 additions and 12 deletions

View File

@ -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]:

View File

@ -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)

View File

@ -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: