diff --git a/invokeai/app/services/image_records/image_records_base.py b/invokeai/app/services/image_records/image_records_base.py index b339f64411..23aa30a1c3 100644 --- a/invokeai/app/services/image_records/image_records_base.py +++ b/invokeai/app/services/image_records/image_records_base.py @@ -6,7 +6,7 @@ from invokeai.app.invocations.fields import MetadataField from invokeai.app.services.shared.pagination import OffsetPaginatedResults from invokeai.app.services.shared.sqlite.sqlite_common import SQLiteDirection -from .image_records_common import ImageCategory, ImageRecord, ImageRecordChanges, OrderByOptions, ResourceOrigin +from .image_records_common import ImageCategory, ImageRecord, ImageRecordChanges, ResourceOrigin class ImageRecordStorageBase(ABC): @@ -38,7 +38,7 @@ class ImageRecordStorageBase(ABC): self, offset: int = 0, limit: int = 10, - order_by: OrderByOptions = OrderByOptions.CREATED_AT, + starred_first: bool = True, order_dir: SQLiteDirection = SQLiteDirection.Descending, image_origin: Optional[ResourceOrigin] = None, categories: Optional[list[ImageCategory]] = None, diff --git a/invokeai/app/services/image_records/image_records_common.py b/invokeai/app/services/image_records/image_records_common.py index 46c4719630..af681e90e1 100644 --- a/invokeai/app/services/image_records/image_records_common.py +++ b/invokeai/app/services/image_records/image_records_common.py @@ -207,13 +207,3 @@ def deserialize_image_record(image_dict: dict) -> ImageRecord: starred=starred, has_workflow=has_workflow, ) - - -class OrderByOptions(str, Enum, metaclass=MetaEnum): - """Options for image ordering - - `created_at`: order by created_at date - - `starred`: order by starred and then created_at - """ - - CREATED_AT = "created_at" - STARRED = "starred" diff --git a/invokeai/app/services/image_records/image_records_sqlite.py b/invokeai/app/services/image_records/image_records_sqlite.py index a78f0837bd..e6196bf5fc 100644 --- a/invokeai/app/services/image_records/image_records_sqlite.py +++ b/invokeai/app/services/image_records/image_records_sqlite.py @@ -17,7 +17,6 @@ from .image_records_common import ( ImageRecordDeleteException, ImageRecordNotFoundException, ImageRecordSaveException, - OrderByOptions, ResourceOrigin, deserialize_image_record, ) @@ -146,7 +145,7 @@ class SqliteImageRecordStorage(ImageRecordStorageBase): self, offset: int = 0, limit: int = 10, - order_by: OrderByOptions = OrderByOptions.CREATED_AT, + starred_first: bool = True, order_dir: SQLiteDirection = SQLiteDirection.Descending, image_origin: Optional[ResourceOrigin] = None, categories: Optional[list[ImageCategory]] = None, @@ -212,9 +211,9 @@ class SqliteImageRecordStorage(ImageRecordStorageBase): """ query_params.append(board_id) - if order_by == OrderByOptions.STARRED: + if starred_first: query_pagination = f"""--sql - ORDER BY images.starred {order_dir}, images.created_at {order_dir} LIMIT ? OFFSET ? + ORDER BY images.starred DESC, images.created_at {order_dir} LIMIT ? OFFSET ? """ else: query_pagination = f"""--sql diff --git a/invokeai/app/services/images/images_base.py b/invokeai/app/services/images/images_base.py index fc6911b1ec..e07a6cc468 100644 --- a/invokeai/app/services/images/images_base.py +++ b/invokeai/app/services/images/images_base.py @@ -8,7 +8,6 @@ from invokeai.app.services.image_records.image_records_common import ( ImageCategory, ImageRecord, ImageRecordChanges, - OrderByOptions, ResourceOrigin, ) from invokeai.app.services.images.images_common import ImageDTO @@ -118,7 +117,7 @@ class ImageServiceABC(ABC): self, offset: int = 0, limit: int = 10, - order_by: OrderByOptions = OrderByOptions.CREATED_AT, + starred_first: bool = True, order_dir: SQLiteDirection = SQLiteDirection.Descending, image_origin: Optional[ResourceOrigin] = None, categories: Optional[list[ImageCategory]] = None, diff --git a/invokeai/app/services/images/images_default.py b/invokeai/app/services/images/images_default.py index 4886f01183..0d792157b8 100644 --- a/invokeai/app/services/images/images_default.py +++ b/invokeai/app/services/images/images_default.py @@ -21,7 +21,6 @@ from ..image_records.image_records_common import ( ImageRecordSaveException, InvalidImageCategoryException, InvalidOriginException, - OrderByOptions, ResourceOrigin, ) from .images_base import ImageServiceABC @@ -209,7 +208,7 @@ class ImageService(ImageServiceABC): self, offset: int = 0, limit: int = 10, - order_by: OrderByOptions = OrderByOptions.CREATED_AT, + starred_first: bool = True, order_dir: SQLiteDirection = SQLiteDirection.Descending, image_origin: Optional[ResourceOrigin] = None, categories: Optional[list[ImageCategory]] = None, @@ -220,7 +219,7 @@ class ImageService(ImageServiceABC): results = self.__invoker.services.image_records.get_many( offset, limit, - order_by, + starred_first, order_dir, image_origin, categories,