From a63dbb2c2d97ba8b98666132a6538198351c2f12 Mon Sep 17 00:00:00 2001 From: maryhipp Date: Thu, 27 Jun 2024 14:27:20 -0400 Subject: [PATCH] (api) change query param to include_archived --- invokeai/app/api/routers/boards.py | 6 +++--- .../services/board_records/board_records_base.py | 6 ++++-- .../services/board_records/board_records_common.py | 2 +- .../services/board_records/board_records_sqlite.py | 13 +++++++------ invokeai/app/services/boards/boards_base.py | 6 ++++-- invokeai/app/services/boards/boards_default.py | 10 ++++++---- 6 files changed, 25 insertions(+), 18 deletions(-) diff --git a/invokeai/app/api/routers/boards.py b/invokeai/app/api/routers/boards.py index 47dc8578a5..19c2b330f0 100644 --- a/invokeai/app/api/routers/boards.py +++ b/invokeai/app/api/routers/boards.py @@ -118,13 +118,13 @@ async def list_boards( all: Optional[bool] = Query(default=None, description="Whether to list all boards"), offset: Optional[int] = Query(default=None, description="The page offset"), limit: Optional[int] = Query(default=None, description="The number of boards per page"), - archived: bool = Query(default=False, description="Whether or not to include archived boards in list"), + include_archived: bool = Query(default=False, description="Whether or not to include archived boards in list"), ) -> Union[OffsetPaginatedResults[BoardDTO], list[BoardDTO]]: """Gets a list of boards""" if all: - return ApiDependencies.invoker.services.boards.get_all(archived) + return ApiDependencies.invoker.services.boards.get_all(include_archived) elif offset is not None and limit is not None: - return ApiDependencies.invoker.services.boards.get_many(offset, limit, archived) + return ApiDependencies.invoker.services.boards.get_many(offset, limit, include_archived) else: raise HTTPException( status_code=400, diff --git a/invokeai/app/services/board_records/board_records_base.py b/invokeai/app/services/board_records/board_records_base.py index eee21f4a7c..9d065b3750 100644 --- a/invokeai/app/services/board_records/board_records_base.py +++ b/invokeai/app/services/board_records/board_records_base.py @@ -39,11 +39,13 @@ class BoardRecordStorageBase(ABC): pass @abstractmethod - def get_many(self, offset: int = 0, limit: int = 10, archived: bool = False) -> OffsetPaginatedResults[BoardRecord]: + def get_many( + self, offset: int = 0, limit: int = 10, include_archived: bool = False + ) -> OffsetPaginatedResults[BoardRecord]: """Gets many board records.""" pass @abstractmethod - def get_all(self, archived: bool = False) -> list[BoardRecord]: + def get_all(self, include_archived: bool = False) -> list[BoardRecord]: """Gets all board records.""" pass diff --git a/invokeai/app/services/board_records/board_records_common.py b/invokeai/app/services/board_records/board_records_common.py index 6c024c738c..f7a51ba8cc 100644 --- a/invokeai/app/services/board_records/board_records_common.py +++ b/invokeai/app/services/board_records/board_records_common.py @@ -22,7 +22,7 @@ class BoardRecord(BaseModelExcludeNull): """The updated timestamp of the image.""" cover_image_name: Optional[str] = Field(default=None, description="The name of the cover image of the board.") """The name of the cover image of the board.""" - archived: Optional[bool] = Field(default=None, description="Whether or not the board is archived.") + archived: bool = Field(default=False, description="Whether or not the board is archived.") """Whether or not the board is archived.""" diff --git a/invokeai/app/services/board_records/board_records_sqlite.py b/invokeai/app/services/board_records/board_records_sqlite.py index 9b976a0e70..9d81e2f1e7 100644 --- a/invokeai/app/services/board_records/board_records_sqlite.py +++ b/invokeai/app/services/board_records/board_records_sqlite.py @@ -138,14 +138,15 @@ class SqliteBoardRecordStorage(BoardRecordStorageBase): self._conn.commit() except sqlite3.Error as e: - print(e) self._conn.rollback() raise BoardRecordSaveException from e finally: self._lock.release() return self.get(board_id) - def get_many(self, offset: int = 0, limit: int = 10, archived: bool = False) -> OffsetPaginatedResults[BoardRecord]: + def get_many( + self, offset: int = 0, limit: int = 10, include_archived: bool = False + ) -> OffsetPaginatedResults[BoardRecord]: try: self._lock.acquire() @@ -159,7 +160,7 @@ class SqliteBoardRecordStorage(BoardRecordStorageBase): """ # Determine archived filter condition - if archived: + if include_archived: archived_filter = "" else: archived_filter = "WHERE archived = 0" @@ -173,7 +174,7 @@ class SqliteBoardRecordStorage(BoardRecordStorageBase): boards = [deserialize_board_record(dict(r)) for r in result] # Determine count query - if archived: + if include_archived: count_query = """ SELECT COUNT(*) FROM boards; @@ -198,7 +199,7 @@ class SqliteBoardRecordStorage(BoardRecordStorageBase): finally: self._lock.release() - def get_all(self, archived: bool = False) -> list[BoardRecord]: + def get_all(self, include_archived: bool = False) -> list[BoardRecord]: try: self._lock.acquire() @@ -209,7 +210,7 @@ class SqliteBoardRecordStorage(BoardRecordStorageBase): ORDER BY created_at DESC """ - if archived: + if include_archived: archived_filter = "" else: archived_filter = "WHERE archived = 0" diff --git a/invokeai/app/services/boards/boards_base.py b/invokeai/app/services/boards/boards_base.py index dbdaa6c5f9..fddd5a7954 100644 --- a/invokeai/app/services/boards/boards_base.py +++ b/invokeai/app/services/boards/boards_base.py @@ -43,11 +43,13 @@ class BoardServiceABC(ABC): pass @abstractmethod - def get_many(self, offset: int = 0, limit: int = 10, archived: bool = False) -> OffsetPaginatedResults[BoardDTO]: + def get_many( + self, offset: int = 0, limit: int = 10, include_archived: bool = False + ) -> OffsetPaginatedResults[BoardDTO]: """Gets many boards.""" pass @abstractmethod - def get_all(self, archived: bool = False) -> list[BoardDTO]: + def get_all(self, include_archived: bool = False) -> list[BoardDTO]: """Gets all boards.""" pass diff --git a/invokeai/app/services/boards/boards_default.py b/invokeai/app/services/boards/boards_default.py index ac8b770230..6457aee1d2 100644 --- a/invokeai/app/services/boards/boards_default.py +++ b/invokeai/app/services/boards/boards_default.py @@ -48,8 +48,10 @@ class BoardService(BoardServiceABC): def delete(self, board_id: str) -> None: self.__invoker.services.board_records.delete(board_id) - def get_many(self, offset: int = 0, limit: int = 10, archived: bool = False) -> OffsetPaginatedResults[BoardDTO]: - board_records = self.__invoker.services.board_records.get_many(offset, limit, archived) + def get_many( + self, offset: int = 0, limit: int = 10, include_archived: bool = False + ) -> OffsetPaginatedResults[BoardDTO]: + board_records = self.__invoker.services.board_records.get_many(offset, limit, include_archived) board_dtos = [] for r in board_records.items: cover_image = self.__invoker.services.image_records.get_most_recent_image_for_board(r.board_id) @@ -63,8 +65,8 @@ class BoardService(BoardServiceABC): return OffsetPaginatedResults[BoardDTO](items=board_dtos, offset=offset, limit=limit, total=len(board_dtos)) - def get_all(self, archived: bool = False) -> list[BoardDTO]: - board_records = self.__invoker.services.board_records.get_all(archived) + def get_all(self, include_archived: bool = False) -> list[BoardDTO]: + board_records = self.__invoker.services.board_records.get_all(include_archived) board_dtos = [] for r in board_records: cover_image = self.__invoker.services.image_records.get_most_recent_image_for_board(r.board_id)