feat(app): remove order_by in favor of starred_first for images records

This commit is contained in:
psychedelicious 2024-06-28 16:27:13 +10:00
parent f268fe126e
commit c96ccae70b
5 changed files with 8 additions and 21 deletions

View File

@ -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,

View File

@ -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"

View File

@ -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

View File

@ -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,

View File

@ -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,