Skip to content

Commit dae775f

Browse files
docs(app): add comments to boards queries
1 parent ab160c4 commit dae775f

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

invokeai/app/services/board_records/board_records_sqlite.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,34 @@
2424
b.created_at,
2525
b.updated_at,
2626
b.archived,
27+
-- Count the number of images in the board, alias image_count
2728
COUNT(
2829
CASE
29-
WHEN i.image_category in ('general')
30-
AND i.is_intermediate = 0 THEN 1
30+
WHEN i.image_category in ('general') -- Images (UI category) are in the 'general' category
31+
AND i.is_intermediate = 0 THEN 1 -- Intermediates are not counted
3132
END
3233
) AS image_count,
34+
-- Count the number of assets in the board, alias asset_count
3335
COUNT(
3436
CASE
35-
WHEN i.image_category in ('control', 'mask', 'user', 'other')
36-
AND i.is_intermediate = 0 THEN 1
37+
WHEN i.image_category in ('control', 'mask', 'user', 'other') -- Assets (UI category) are in one of these categories
38+
AND i.is_intermediate = 0 THEN 1 -- Intermediates are not counted
3739
END
3840
) AS asset_count,
41+
-- Get the name of the the most recent image in the board, alias cover_image_name
3942
(
4043
SELECT bi.image_name
4144
FROM board_images bi
4245
JOIN images i ON bi.image_name = i.image_name
4346
WHERE bi.board_id = b.board_id
44-
AND i.is_intermediate = 0
45-
ORDER BY i.created_at DESC
47+
AND i.is_intermediate = 0 -- Intermediates cannot be cover images
48+
ORDER BY i.created_at DESC -- Sort by created_at to get the most recent image
4649
LIMIT 1
4750
) AS cover_image_name
4851
FROM boards b
4952
LEFT JOIN board_images bi ON b.board_id = bi.board_id
5053
LEFT JOIN images i ON bi.image_name = i.image_name
54+
-- This query is missing a GROUP BY clause! The utility functions using this query must add it
5155
"""
5256

5357

@@ -279,15 +283,15 @@ def get_uncategorized_image_counts(self) -> UncategorizedImageCounts:
279283
query = """
280284
SELECT
281285
CASE
282-
WHEN i.image_category = 'general' THEN 'images'
283-
ELSE 'assets'
286+
WHEN i.image_category = 'general' THEN 'images' -- Images (UI category) includes images in the 'general' DB category
287+
ELSE 'assets' -- Assets (UI category) includes all other DB categories: 'control', 'mask', 'user', 'other'
284288
END AS category_type,
285289
COUNT(*) AS unassigned_count
286290
FROM images i
287291
LEFT JOIN board_images bi ON i.image_name = bi.image_name
288-
WHERE bi.board_id IS NULL
289-
AND i.is_intermediate = 0
290-
GROUP BY category_type;
292+
WHERE bi.board_id IS NULL -- Uncategorized images have no board
293+
AND i.is_intermediate = 0 -- Omit intermediates from the counts
294+
GROUP BY category_type; -- Group by category_type alias, as derived from the image_category column earlier
291295
"""
292296
self._cursor.execute(query)
293297
results = self._cursor.fetchall()

0 commit comments

Comments
 (0)