|
24 | 24 | b.created_at,
|
25 | 25 | b.updated_at,
|
26 | 26 | b.archived,
|
| 27 | + -- Count the number of images in the board, alias image_count |
27 | 28 | COUNT(
|
28 | 29 | 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 |
31 | 32 | END
|
32 | 33 | ) AS image_count,
|
| 34 | + -- Count the number of assets in the board, alias asset_count |
33 | 35 | COUNT(
|
34 | 36 | 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 |
37 | 39 | END
|
38 | 40 | ) AS asset_count,
|
| 41 | + -- Get the name of the the most recent image in the board, alias cover_image_name |
39 | 42 | (
|
40 | 43 | SELECT bi.image_name
|
41 | 44 | FROM board_images bi
|
42 | 45 | JOIN images i ON bi.image_name = i.image_name
|
43 | 46 | 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 |
46 | 49 | LIMIT 1
|
47 | 50 | ) AS cover_image_name
|
48 | 51 | FROM boards b
|
49 | 52 | LEFT JOIN board_images bi ON b.board_id = bi.board_id
|
50 | 53 | 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 |
51 | 55 | """
|
52 | 56 |
|
53 | 57 |
|
@@ -279,15 +283,15 @@ def get_uncategorized_image_counts(self) -> UncategorizedImageCounts:
|
279 | 283 | query = """
|
280 | 284 | SELECT
|
281 | 285 | 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' |
284 | 288 | END AS category_type,
|
285 | 289 | COUNT(*) AS unassigned_count
|
286 | 290 | FROM images i
|
287 | 291 | 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 |
291 | 295 | """
|
292 | 296 | self._cursor.execute(query)
|
293 | 297 | results = self._cursor.fetchall()
|
|
0 commit comments