Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(api): add starred filter to gallery listings
Josh Corbett6b9780369ad0
diff --git a/invokeai/app/api/routers/gallery.py b/invokeai/app/api/routers/gallery.pyindex 5b33897e83..102c287980 100644--- a/invokeai/app/api/routers/gallery.py+++ b/invokeai/app/api/routers/gallery.py@@ -38,6 +38,10 @@ def list_gallery_items(limit: int = Query(default=10, ge=0, le=MAX_PAGE_SIZE, description="The number of items per page"),order_dir: SQLiteDirection = Query(default=SQLiteDirection.Descending, description="The order of sort"),starred_first: bool = Query(default=True, description="Whether to sort by starred items first"),+ starred: Optional[bool] = Query(+ default=None,+ description="Filter by starred state: true for starred items only, false for unstarred only. Omit to include both.",+ ),search_term: Optional[str] = Query(default=None, description="The term to search for"),created_from: Optional[date] = Query(default=None, description="Inclusive start date (YYYY-MM-DD) to filter by created_at."@@ -64,6 +68,7 @@ def list_gallery_items(is_admin=current_user.is_admin,created_from=created_from.isoformat() if created_from else None,created_to=created_to.isoformat() if created_to else None,+ starred=starred,)@@ -96,6 +101,10 @@ def list_gallery_item_names(),order_dir: SQLiteDirection = Query(default=SQLiteDirection.Descending, description="The order of sort"),starred_first: bool = Query(default=True, description="Whether to sort by starred items first"),+ starred: Optional[bool] = Query(+ default=None,+ description="Filter by starred state: true for starred items only, false for unstarred only. Omit to include both.",+ ),search_term: Optional[str] = Query(default=None, description="The term to search for"),) -> GalleryItemNames:"""Returns the ordered flat list of item names — used to drive virtualized gallery selection.@@ -120,6 +129,7 @@ def list_gallery_item_names(created_date=created_date,created_from=created_from.isoformat() if created_from else None,created_to=created_to.isoformat() if created_to else None,+ starred=starred,)except Exception:raise HTTPException(status_code=500, detail="Failed to get gallery item names")@@ -145,6 +155,10 @@ def get_gallery_item_names(),order_dir: SQLiteDirection = Query(default=SQLiteDirection.Descending, description="The order of sort"),starred_first: bool = Query(default=True, description="Whether to sort by starred items first"),+ starred: Optional[bool] = Query(+ default=None,+ description="Filter by starred state: true for starred items only, false for unstarred only. Omit to include both.",+ ),search_term: Optional[str] = Query(default=None, description="The term to search for"),created_from: Optional[date] = Query(default=None, description="Inclusive start date (YYYY-MM-DD) to filter by created_at."@@ -175,6 +189,7 @@ def get_gallery_item_names(is_admin=current_user.is_admin,created_from=created_from.isoformat() if created_from else None,created_to=created_to.isoformat() if created_to else None,+ starred=starred,)except Exception:raise HTTPException(status_code=500, detail="Failed to get gallery item names")diff --git a/invokeai/app/api/routers/virtual_boards.py b/invokeai/app/api/routers/virtual_boards.pyindex 9837cbd899..2742b4ef96 100644--- a/invokeai/app/api/routers/virtual_boards.py+++ b/invokeai/app/api/routers/virtual_boards.py@@ -72,6 +72,10 @@ def list_virtual_board_item_names_by_date(current_user: CurrentUserOrDefault,date: str = Path(description="The ISO date string, e.g. '2026-03-18'"),starred_first: bool = Query(default=True, description="Whether to sort starred items first"),+ starred: bool | None = Query(+ default=None,+ description="Filter by starred state: true for starred items only, false for unstarred only. Omit to include both.",+ ),order_dir: SQLiteDirection = Query(default=SQLiteDirection.Descending, description="The sort direction"),categories: list[ImageCategory] | None = Query(default=None, description="The categories of items to include"),search_term: str | None = Query(default=None, description="Search term to filter items"),@@ -91,6 +95,7 @@ def list_virtual_board_item_names_by_date(user_id=current_user.user_id,is_admin=current_user.is_admin,created_date=date,+ starred=starred,)except Exception:raise HTTPException(status_code=500, detail="Failed to get gallery item names for date")diff --git a/invokeai/app/services/gallery/gallery_base.py b/invokeai/app/services/gallery/gallery_base.pyindex 608425fefd..51b4f007f7 100644--- a/invokeai/app/services/gallery/gallery_base.py+++ b/invokeai/app/services/gallery/gallery_base.py@@ -32,6 +32,7 @@ class GalleryServiceABC(ABC):is_admin: bool = False,created_from: Optional[str] = None,created_to: Optional[str] = None,+ starred: Optional[bool] = None,) -> OffsetPaginatedResults[GalleryItem]:"""Lists a paginated, time-sorted stream of image + video items."""pass@@ -51,6 +52,7 @@ class GalleryServiceABC(ABC):created_date: Optional[str] = None,created_from: Optional[str] = None,created_to: Optional[str] = None,+ starred: Optional[bool] = None,) -> GalleryItemNamesResult:"""Returns ordered (kind, name) refs for optimistic UI / virtualized lists.@@ -74,6 +76,7 @@ class GalleryServiceABC(ABC):created_date: Optional[str] = None,created_from: Optional[str] = None,created_to: Optional[str] = None,+ starred: Optional[bool] = None,) -> GalleryItemNames:"""Returns the ordered flat name list for optimistic UI / virtualized lists.@@ -81,6 +84,8 @@ class GalleryServiceABC(ABC):date-based virtual boards.`created_from` and `created_to` are inclusive YYYY-MM-DD bounds on created_at (UTC days).++ `starred` restricts to starred (`True`) or unstarred (`False`) items; `None` applies no filter."""passdiff --git a/invokeai/app/services/gallery/gallery_default.py b/invokeai/app/services/gallery/gallery_default.pyindex c73489a201..bb4bc44b1c 100644--- a/invokeai/app/services/gallery/gallery_default.py+++ b/invokeai/app/services/gallery/gallery_default.py@@ -50,6 +50,7 @@ class SqliteGalleryService(GalleryServiceABC):is_admin: bool = False,created_from: Optional[str] = None,created_to: Optional[str] = None,+ starred: Optional[bool] = None,) -> OffsetPaginatedResults[GalleryItem]:image_half, image_params, image_count_query = self._build_half(kind="image",@@ -62,6 +63,7 @@ class SqliteGalleryService(GalleryServiceABC):is_admin=is_admin,created_from=created_from,created_to=created_to,+ starred=starred,)video_half, video_params, video_count_query = self._build_half(kind="video",@@ -74,6 +76,7 @@ class SqliteGalleryService(GalleryServiceABC):is_admin=is_admin,created_from=created_from,created_to=created_to,+ starred=starred,)order_clause = self._build_order_clause(starred_first, order_dir)@@ -121,6 +124,7 @@ class SqliteGalleryService(GalleryServiceABC):created_date: Optional[str],created_from: Optional[str],created_to: Optional[str],+ starred: Optional[bool],) -> tuple[list[sqlite3.Row], int]:"""Runs the ordered name query and returns its rows plus the starred count.@@ -140,6 +144,7 @@ class SqliteGalleryService(GalleryServiceABC):created_date=created_date,created_from=created_from,created_to=created_to,+ starred=starred,)video_half, video_params, _ = self._build_half(kind="video",@@ -154,6 +159,7 @@ class SqliteGalleryService(GalleryServiceABC):created_date=created_date,created_from=created_from,created_to=created_to,+ starred=starred,)order_clause = self._build_order_clause(starred_first, order_dir)@@ -192,6 +198,7 @@ class SqliteGalleryService(GalleryServiceABC):created_date: Optional[str] = None,created_from: Optional[str] = None,created_to: Optional[str] = None,+ starred: Optional[bool] = None,) -> GalleryItemNamesResult:rows, starred_count = self._query_name_rows(starred_first=starred_first,@@ -206,6 +213,7 @@ class SqliteGalleryService(GalleryServiceABC):created_date=created_date,created_from=created_from,created_to=created_to,+ starred=starred,)refs = [GalleryItemRef(kind=GalleryItemKind(row["kind"]), name=row["name"]) for row in rows]return GalleryItemNamesResult(items=refs, starred_count=starred_count, total_count=len(refs))@@ -224,6 +232,7 @@ class SqliteGalleryService(GalleryServiceABC):created_date: Optional[str] = None,created_from: Optional[str] = None,created_to: Optional[str] = None,+ starred: Optional[bool] = None,) -> GalleryItemNames:rows, starred_count = self._query_name_rows(starred_first=starred_first,@@ -238,6 +247,7 @@ class SqliteGalleryService(GalleryServiceABC):created_date=created_date,created_from=created_from,created_to=created_to,+ starred=starred,)# A list comprehension over the raw column, deliberately: building one model per row# is what made the deprecated variant expensive.@@ -435,6 +445,7 @@ class SqliteGalleryService(GalleryServiceABC):created_date: Optional[str] = None,created_from: Optional[str] = None,created_to: Optional[str] = None,+ starred: Optional[bool] = None,) -> tuple[str, list[Union[int, str, bool]], str]:"""Builds one half of the union (either `images` or `videos`).@@ -522,6 +533,10 @@ class SqliteGalleryService(GalleryServiceABC):conditions += f" AND {base_table}.is_intermediate = ? "params.append(is_intermediate)+ if starred is not None:+ conditions += f" AND {base_table}.starred = ? "+ params.append(starred)+if created_date is not None:conditions += f" AND DATE({base_table}.created_at) = ? "params.append(created_date)diff --git a/invokeai/frontend/web/openapi.json b/invokeai/frontend/web/openapi.jsonindex 7d415ea914..e3e26ca43f 100644--- a/invokeai/frontend/web/openapi.json+++ b/invokeai/frontend/web/openapi.json@@ -8116,6 +8116,24 @@},"description": "Whether to sort by starred items first"},+ {+ "name": "starred",+ "in": "query",+ "required": false,+ "schema": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ],+ "description": "Filter by starred state: true for starred items only, false for unstarred only. Omit to include both.",+ "title": "Starred"+ },+ "description": "Filter by starred state: true for starred items only, false for unstarred only. Omit to include both."+ },{"name": "search_term","in": "query",@@ -8363,6 +8381,24 @@},"description": "Whether to sort by starred items first"},+ {+ "name": "starred",+ "in": "query",+ "required": false,+ "schema": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ],+ "description": "Filter by starred state: true for starred items only, false for unstarred only. Omit to include both.",+ "title": "Starred"+ },+ "description": "Filter by starred state: true for starred items only, false for unstarred only. Omit to include both."+ },{"name": "search_term","in": "query",@@ -8517,6 +8553,24 @@},"description": "Whether to sort by starred items first"},+ {+ "name": "starred",+ "in": "query",+ "required": false,+ "schema": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ],+ "description": "Filter by starred state: true for starred items only, false for unstarred only. Omit to include both.",+ "title": "Starred"+ },+ "description": "Filter by starred state: true for starred items only, false for unstarred only. Omit to include both."+ },{"name": "search_term","in": "query",@@ -9396,6 +9450,24 @@},"description": "Whether to sort starred items first"},+ {+ "name": "starred",+ "in": "query",+ "required": false,+ "schema": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ],+ "description": "Filter by starred state: true for starred items only, false for unstarred only. Omit to include both.",+ "title": "Starred"+ },+ "description": "Filter by starred state: true for starred items only, false for unstarred only. Omit to include both."+ },{"name": "order_dir","in": "query",diff --git a/invokeai/frontend/web/src/services/api/schema.ts b/invokeai/frontend/web/src/services/api/schema.tsindex d532ec2528..6cb7bccf17 100644--- a/invokeai/frontend/web/src/services/api/schema.ts+++ b/invokeai/frontend/web/src/services/api/schema.ts@@ -49237,6 +49237,8 @@ export interface operations {order_dir?: components["schemas"]["SQLiteDirection"];/** @description Whether to sort by starred items first */starred_first?: boolean;+ /** @description Filter by starred state: true for starred items only, false for unstarred only. Omit to include both. */+ starred?: boolean | null;/** @description The term to search for */search_term?: string | null;/** @description Inclusive start date (YYYY-MM-DD) to filter by created_at. */@@ -49291,6 +49293,8 @@ export interface operations {order_dir?: components["schemas"]["SQLiteDirection"];/** @description Whether to sort by starred items first */starred_first?: boolean;+ /** @description Filter by starred state: true for starred items only, false for unstarred only. Omit to include both. */+ starred?: boolean | null;/** @description The term to search for */search_term?: string | null;};@@ -49335,6 +49339,8 @@ export interface operations {order_dir?: components["schemas"]["SQLiteDirection"];/** @description Whether to sort by starred items first */starred_first?: boolean;+ /** @description Filter by starred state: true for starred items only, false for unstarred only. Omit to include both. */+ starred?: boolean | null;/** @description The term to search for */search_term?: string | null;/** @description Inclusive start date (YYYY-MM-DD) to filter by created_at. */@@ -49780,6 +49786,8 @@ export interface operations {query?: {/** @description Whether to sort starred items first */starred_first?: boolean;+ /** @description Filter by starred state: true for starred items only, false for unstarred only. Omit to include both. */+ starred?: boolean | null;/** @description The sort direction */order_dir?: components["schemas"]["SQLiteDirection"];/** @description The categories of items to include */diff --git a/invokeai/frontend/webv2/scripts/mock-backend-fixtures.test.mjs b/invokeai/frontend/webv2/scripts/mock-backend-fixtures.test.mjsindex f4234b4679..c154220855 100644--- a/invokeai/frontend/webv2/scripts/mock-backend-fixtures.test.mjs+++ b/invokeai/frontend/webv2/scripts/mock-backend-fixtures.test.mjs@@ -330,6 +330,34 @@ test('date-board item names preserve the mixed gallery ordering and filter contr});});+test('starred filter narrows gallery items, names, and date boards consistently', async () => {+ await withRepresentativeBackend(async (backend) => {+ const query = 'categories=general&is_intermediate=false&limit=1000&offset=0';+ const all = await getJson(backend, `/api/v1/gallery/items/?${query}`);+ const starredOnly = await getJson(backend, `/api/v1/gallery/items/?${query}&starred=true`);+ const unstarred = await getJson(backend, `/api/v1/gallery/items/?${query}&starred=false`);++ assert.ok(starredOnly.items.every((item) => item.starred === true));+ assert.ok(starredOnly.items.some((item) => item.kind === 'video'));+ assert.ok(unstarred.items.every((item) => item.starred === false));+ assert.equal(starredOnly.total, all.items.filter((item) => item.starred).length);+ assert.equal(starredOnly.total + unstarred.total, all.total);++ const names = await getJson(+ backend,+ '/api/v1/gallery/items/names?categories=general&is_intermediate=false&starred_first=true&starred=false'+ );+ assert.equal(names.starred_count, 0);+ assert.equal(names.total_count, unstarred.total);++ const dateQuery = '/api/v1/virtual_boards/by_date/2026-01-15/item_names?categories=general&is_intermediate=false';+ const dated = await getJson(backend, dateQuery);+ const datedStarred = await getJson(backend, `${dateQuery}&starred=true`);+ assert.equal(datedStarred.total_count, dated.starred_count);+ assert.ok(datedStarred.total_count > 0);+ });+});+test('video DTO, Details, poster, full media, HEAD, and Range routes use the checked-in assets', async () => {await withRepresentativeBackend(async (backend) => {const name = 'fixture-video-001.mp4';diff --git a/invokeai/frontend/webv2/scripts/mock-backend.mjs b/invokeai/frontend/webv2/scripts/mock-backend.mjsindex eae6c832c1..8af09fb0f2 100644--- a/invokeai/frontend/webv2/scripts/mock-backend.mjs+++ b/invokeai/frontend/webv2/scripts/mock-backend.mjs@@ -281,6 +281,7 @@ const filterGalleryItems = (state, url, { createdDate } = {}) => {const createdFrom = url.searchParams.get('created_from');const createdTo = url.searchParams.get('created_to');const intermediate = getOptionalBoolean(url, 'is_intermediate');+ const starred = getOptionalBoolean(url, 'starred');const searchTerm = url.searchParams.get('search_term')?.trim().toLocaleLowerCase() ?? '';return getGalleryCandidates(state)@@ -294,6 +295,9 @@ const filterGalleryItems = (state, url, { createdDate } = {}) => {if (intermediate !== undefined && item.is_intermediate !== intermediate) {return false;}+ if (starred !== undefined && Boolean(item.starred) !== starred) {+ return false;+ }if (createdDate && item.created_at.slice(0, 10) !== createdDate) {return false;}diff --git a/tests/app/routers/test_gallery.py b/tests/app/routers/test_gallery.pyindex bb2338664c..b6996234b2 100644--- a/tests/app/routers/test_gallery.py+++ b/tests/app/routers/test_gallery.py@@ -62,3 +62,38 @@ def test_gallery_list_endpoints_reject_invalid_created_range_dates(response = client.get(path, params={param: "2026-02-31"})assert response.status_code == 422+++ ("path", "service_index"),+ [("/api/v1/gallery/items/", 0), ("/api/v1/gallery/items/names", 1), ("/api/v1/gallery/item_names", 2)],+)[email protected](("value", "expected"), [("true", True), ("false", False), (None, None)])+def test_gallery_list_endpoints_forward_starred_filter(+ monkeypatch: Any,+ mock_invoker: Invoker,+ client: TestClient,+ path: str,+ service_index: int,+ value: str | None,+ expected: bool | None,+) -> None:+ service_calls = _prepare_gallery_router_test(monkeypatch, mock_invoker)++ response = client.get(path, params={} if value is None else {"starred": value})++ assert response.status_code == 200+ assert service_calls[service_index].call_args.kwargs["starred"] is expected+++ "path", ["/api/v1/gallery/items/", "/api/v1/gallery/items/names", "/api/v1/gallery/item_names"]+)+def test_gallery_list_endpoints_reject_non_boolean_starred(+ monkeypatch: Any, mock_invoker: Invoker, client: TestClient, path: str+) -> None:+ _prepare_gallery_router_test(monkeypatch, mock_invoker)++ response = client.get(path, params={"starred": "maybe"})++ assert response.status_code == 422diff --git a/tests/app/routers/test_gallery_item_names.py b/tests/app/routers/test_gallery_item_names.pyindex 0dec1103b2..b86af4a802 100644--- a/tests/app/routers/test_gallery_item_names.py+++ b/tests/app/routers/test_gallery_item_names.py@@ -18,6 +18,7 @@ from fastapi.testclient import TestClientfrom invokeai.app.services.image_records.image_records_common import ImageCategory, ResourceOriginfrom invokeai.app.services.invoker import Invoker+from invokeai.app.services.video_records.video_records_common import VideoRecordChangesITEM_NAMES_URL = "/api/v1/gallery/item_names"DEPRECATED_URL = "/api/v1/gallery/items/names"@@ -160,3 +161,25 @@ def test_marked_deprecated_in_the_openapi_schema(client: TestClient):"/api/v1/virtual_boards/by_date/{date}/item_names",):assert schema["paths"][path]["get"]["deprecated"] is True, f"{path} should be marked deprecated"+++def test_starred_filter_matches_the_deprecated_endpoint(client: TestClient, user1_token: str, mock_invoker: Invoker):+ """Both name shapes must narrow to the same rows under the `starred` filter."""+ user1 = mock_invoker.services.users.get_by_email("[email protected]")+ assert user1 is not None++ _save_image(mock_invoker, "img-plain.png", user1.user_id)+ _save_video(mock_invoker, "vid-starred.mp4", user1.user_id)+ mock_invoker.services.video_records.update("vid-starred.mp4", VideoRecordChanges(starred=True))++ headers = {"Authorization": f"Bearer {user1_token}"}+ for starred, expected in (("true", ["vid-starred.mp4"]), ("false", ["img-plain.png"])):+ new = client.get(ITEM_NAMES_URL, params={"starred": starred}, headers=headers)+ old = client.get(DEPRECATED_URL, params={"starred": starred}, headers=headers)+ assert new.status_code == status.HTTP_200_OK+ assert old.status_code == status.HTTP_200_OK++ assert new.json()["item_names"] == expected+ assert new.json()["item_names"] == [item["name"] for item in old.json()["items"]]+ assert new.json()["total_count"] == old.json()["total_count"] == 1+ assert new.json()["starred_count"] == old.json()["starred_count"]diff --git a/tests/app/routers/test_virtual_boards.py b/tests/app/routers/test_virtual_boards.pyindex f5468dcc80..7b885126c9 100644--- a/tests/app/routers/test_virtual_boards.py+++ b/tests/app/routers/test_virtual_boards.py@@ -9,7 +9,11 @@ from typing import Anyfrom fastapi import statusfrom fastapi.testclient import TestClient-from invokeai.app.services.image_records.image_records_common import ImageCategory, ResourceOrigin+from invokeai.app.services.image_records.image_records_common import (+ ImageCategory,+ ImageRecordChanges,+ ResourceOrigin,+)from invokeai.app.services.invoker import Invoker@@ -145,3 +149,30 @@ def test_item_names_by_date_returns_video_refs(client: TestClient, user1_token:refs = {(item["kind"], item["name"]) for item in body["items"]}assert refs == {("image", "u1-mixed.png"), ("video", "u1-mixed.mp4")}assert body["total_count"] == 2+++def test_item_names_by_date_forwards_starred_filter(client: TestClient, user1_token: str, mock_invoker: Invoker):+ """`starred` narrows a date board to starred or unstarred items and reports the narrowed total."""+ user1 = mock_invoker.services.users.get_by_email("[email protected]")+ assert user1 is not None++ _save_image(mock_invoker, "u1-starred.png", user1.user_id)+ _save_image(mock_invoker, "u1-plain.png", user1.user_id)+ mock_invoker.services.image_records.update("u1-starred.png", ImageRecordChanges(starred=True))++ headers = {"Authorization": f"Bearer {user1_token}"}+ date = client.get("/api/v1/virtual_boards/by_date", headers=headers).json()[0]["date"]++ starred = client.get(+ f"/api/v1/virtual_boards/by_date/{date}/item_names", params={"starred": "true"}, headers=headers+ )+ unstarred = client.get(+ f"/api/v1/virtual_boards/by_date/{date}/item_names", params={"starred": "false"}, headers=headers+ )++ assert starred.status_code == status.HTTP_200_OK+ assert [item["name"] for item in starred.json()["items"]] == ["u1-starred.png"]+ assert starred.json()["total_count"] == 1+ assert unstarred.status_code == status.HTTP_200_OK+ assert [item["name"] for item in unstarred.json()["items"]] == ["u1-plain.png"]+ assert unstarred.json()["total_count"] == 1diff --git a/tests/app/services/gallery/test_gallery_default.py b/tests/app/services/gallery/test_gallery_default.pyindex 8f4c5d2788..1c617015f5 100644--- a/tests/app/services/gallery/test_gallery_default.py+++ b/tests/app/services/gallery/test_gallery_default.py@@ -157,6 +157,12 @@ def _backdate(services, table: str, name_col: str, name: str, created_at: str) -cursor.execute(f"UPDATE {table} SET created_at = ? WHERE {name_col} = ?", (created_at, name))+def _star(services, table: str, name_col: str, name: str) -> None:+ db = services["images"]._db+ with db.transaction() as cursor:+ cursor.execute(f"UPDATE {table} SET starred = 1 WHERE {name_col} = ?", (name,))++def _start_gallery_for_item_results(services) -> None:"""Provide the URL service dependency required when gallery rows become item DTOs."""urls = SimpleNamespace(@@ -186,6 +192,126 @@ def _seed_created_range(services) -> None:_backdate(services, table, name_col, name, created_at)+def _seed_starred(services) -> None:+ """Alice owns a starred and a plain item of each kind; Bob owns one starred image."""+ for name in ("starred.png", "plain.png"):+ _save_image(services["images"], name, user_id="alice")+ for name in ("starred.mp4", "plain.mp4"):+ _save_video(services["videos"], name, user_id="alice")+ _save_image(services["images"], "bob-starred.png", user_id="bob")++ for table, name_col, name, created_at in [+ ("images", "image_name", "starred.png", "2026-04-01 10:00:00"),+ ("videos", "video_name", "starred.mp4", "2026-04-01 11:00:00"),+ ("images", "image_name", "plain.png", "2026-04-02 10:00:00"),+ ("videos", "video_name", "plain.mp4", "2026-04-02 11:00:00"),+ ("images", "image_name", "bob-starred.png", "2026-04-02 12:00:00"),+ ]:+ _backdate(services, table, name_col, name, created_at)+ for table, name_col, name in [+ ("images", "image_name", "starred.png"),+ ("videos", "video_name", "starred.mp4"),+ ("images", "image_name", "bob-starred.png"),+ ]:+ _star(services, table, name_col, name)+++class TestStarredFiltering:+ def test_list_items_starred_true_returns_only_starred_of_both_kinds_with_total(self, services) -> None:+ _seed_starred(services)+ _start_gallery_for_item_results(services)++ result = services["gallery"].list_items(limit=10, user_id="alice", is_admin=False, starred=True)++ assert [(item.kind, item.name) for item in result.items] == [+ (GalleryItemKind.VIDEO, "starred.mp4"),+ (GalleryItemKind.IMAGE, "starred.png"),+ ]+ assert result.total == 2++ def test_list_items_starred_false_returns_only_unstarred(self, services) -> None:+ _seed_starred(services)+ _start_gallery_for_item_results(services)++ result = services["gallery"].list_items(limit=10, user_id="alice", is_admin=False, starred=False)++ assert {(item.kind, item.name) for item in result.items} == {+ (GalleryItemKind.VIDEO, "plain.mp4"),+ (GalleryItemKind.IMAGE, "plain.png"),+ }+ assert result.total == 2++ def test_list_items_without_starred_is_unfiltered(self, services) -> None:+ _seed_starred(services)+ _start_gallery_for_item_results(services)++ result = services["gallery"].list_items(limit=10, user_id="alice", is_admin=False)++ assert result.total == 4++ def test_starred_filter_respects_non_admin_isolation(self, services) -> None:+ _seed_starred(services)+ gallery = services["gallery"]++ as_admin = gallery.list_item_names(user_id="alice", is_admin=True, starred=True)+ as_user = gallery.list_item_names(user_id="alice", is_admin=False, starred=True)++ assert {item.name for item in as_admin.items} == {"starred.png", "starred.mp4", "bob-starred.png"}+ assert {item.name for item in as_user.items} == {"starred.png", "starred.mp4"}++ def test_starred_filter_composes_with_board_scope(self, services) -> None:+ _seed_starred(services)+ board = services["boards"].save("Board", "alice")+ services["board_images"].add_image_to_board(board.board_id, "starred.png")+ services["board_images"].add_image_to_board(board.board_id, "plain.png")+ gallery = services["gallery"]++ on_board = gallery.list_item_names(board_id=board.board_id, user_id="alice", is_admin=False, starred=True)+ off_board = gallery.list_item_names(board_id="none", user_id="alice", is_admin=False, starred=True)++ assert [item.name for item in on_board.items] == ["starred.png"]+ assert [item.name for item in off_board.items] == ["starred.mp4"]++ def test_starred_filter_composes_with_date_filters_and_search(self, services) -> None:+ _seed_starred(services)+ gallery = services["gallery"]++ by_date = gallery.list_item_names(user_id="alice", is_admin=False, created_date="2026-04-01", starred=True)+ by_range = gallery.get_item_names(+ user_id="alice",+ is_admin=False,+ created_from="2026-04-02",+ created_to="2026-04-02",+ starred=False,+ )+ by_search = gallery.get_item_names(user_id="alice", is_admin=False, search_term="2026-04-01 11", starred=True)++ assert {item.name for item in by_date.items} == {"starred.png", "starred.mp4"}+ assert set(by_range.item_names) == {"plain.png", "plain.mp4"}+ assert by_search.item_names == ["starred.mp4"]++ def test_name_lists_keep_starred_count_semantics_under_filter(self, services) -> None:+ _seed_starred(services)+ gallery = services["gallery"]++ starred = gallery.list_item_names(user_id="alice", is_admin=False, starred=True)+ unstarred = gallery.list_item_names(user_id="alice", is_admin=False, starred=False)+ unsorted = gallery.list_item_names(user_id="alice", is_admin=False, starred=True, starred_first=False)+ flat = gallery.get_item_names(user_id="alice", is_admin=False, starred=True)++ assert starred.starred_count == starred.total_count == 2+ assert unstarred.starred_count == 0+ assert unsorted.starred_count == 0+ assert flat.item_names == [item.name for item in starred.items]++ def test_starred_first_ordering_is_unchanged_when_unfiltered(self, services) -> None:+ _seed_starred(services)++ names = [item.name for item in services["gallery"].list_item_names(user_id="alice", is_admin=False).items]++ assert names == ["starred.mp4", "starred.png", "plain.mp4", "plain.png"]++class TestGetDatesPolymorphic:def test_video_only_date_appears(self, services) -> None:# A date with videos and no images must still produce a virtual board — with the@@ -436,6 +562,7 @@ class TestGalleryQueryPlans:{"user_id": "alice", "is_admin": False},{"user_id": "alice", "is_admin": False, "order_dir": SQLiteDirection.Ascending},{"user_id": "alice", "is_admin": False, "starred_first": False},+ {"user_id": "alice", "is_admin": False, "starred": True},],)def test_name_shapes_do_not_force_indexes(self, services, kwargs) -> None:@@ -454,6 +581,30 @@ class TestGalleryQueryPlans:assert "INDEXED BY" not in statementassert "NOT INDEXED" not in statement+ def test_starred_filter_searches_the_starred_index(self, services) -> None:+ # The bounded starred strip asks for `starred = 1` on every board visit, so the+ # filter must be served by idx_*_starred rather than a table scan per half.+ _save_image(services["images"], "starred.png", user_id="alice")+ _save_image(services["images"], "plain.png", user_id="alice")+ _save_video(services["videos"], "starred.mp4", user_id="alice")+ _save_video(services["videos"], "plain.mp4", user_id="alice")+ _star(services, "images", "image_name", "starred.png")+ _star(services, "videos", "video_name", "starred.mp4")++ result, _, details = _capture_plan(+ services,+ lambda: services["gallery"].list_item_names(+ categories=[ImageCategory.GENERAL],+ is_intermediate=False,+ is_admin=True,+ starred=True,+ ),+ "UNION ALL",+ )++ assert result.total_count == 2+ assert not any(detail.startswith(("SCAN images", "SCAN videos")) for detail in details)+def test_explicit_board_starts_from_mixed_membership(self, services) -> None:board = services["boards"].save("Small", "alice")_save_image(services["images"], "image.png", user_id="alice")