Skip to content

Commit 338c74d

Browse files
feat(app): add get_uncategorized_image_counts method on board_records service
1 parent fb1130c commit 338c74d

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

invokeai/app/services/board_records/board_records_base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from abc import ABC, abstractmethod
22

3-
from invokeai.app.services.board_records.board_records_common import BoardChanges, BoardRecord
3+
from invokeai.app.services.board_records.board_records_common import BoardChanges, BoardRecord, UncategorizedImageCounts
44
from invokeai.app.services.shared.pagination import OffsetPaginatedResults
55

66

@@ -48,3 +48,8 @@ def get_many(
4848
def get_all(self, include_archived: bool = False) -> list[BoardRecord]:
4949
"""Gets all board records."""
5050
pass
51+
52+
@abstractmethod
53+
def get_uncategorized_image_counts(self) -> UncategorizedImageCounts:
54+
"""Gets count of images and assets for uncategorized images (images with no board assocation)."""
55+
pass

invokeai/app/services/board_records/board_records_common.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,8 @@ class BoardRecordDeleteException(Exception):
7979

8080
def __init__(self, message="Board record not deleted"):
8181
super().__init__(message)
82+
83+
84+
class UncategorizedImageCounts(BaseModel):
85+
image_count: int = Field(description="The number of uncategorized images.")
86+
asset_count: int = Field(description="The number of uncategorized assets.")

invokeai/app/services/board_records/board_records_sqlite.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
BoardRecordDeleteException,
1010
BoardRecordNotFoundException,
1111
BoardRecordSaveException,
12+
UncategorizedImageCounts,
1213
deserialize_board_record,
1314
)
1415
from invokeai.app.services.shared.pagination import OffsetPaginatedResults
@@ -228,3 +229,28 @@ def get_all(self, include_archived: bool = False) -> list[BoardRecord]:
228229
raise e
229230
finally:
230231
self._lock.release()
232+
233+
def get_uncategorized_image_counts(self) -> UncategorizedImageCounts:
234+
try:
235+
self._lock.acquire()
236+
query = """
237+
SELECT
238+
CASE
239+
WHEN i.image_category = 'general' THEN 'images'
240+
ELSE 'assets'
241+
END AS category_type,
242+
COUNT(*) AS unassigned_count
243+
FROM images i
244+
LEFT JOIN board_images bi ON i.image_name = bi.image_name
245+
WHERE i.image_category IN ('general', 'control', 'mask', 'user', 'other')
246+
AND bi.board_id IS NULL
247+
AND i.is_intermediate = 0
248+
GROUP BY category_type;
249+
"""
250+
self._cursor.execute(query)
251+
results = self._cursor.fetchall()
252+
image_count = results[0][1]
253+
asset_count = results[1][1]
254+
return UncategorizedImageCounts(image_count=image_count, asset_count=asset_count)
255+
finally:
256+
self._lock.release()

0 commit comments

Comments
 (0)