-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use SQL instead of python to retrieve image count, asset count and board cover image. This reduces the number of SQL queries needed to list all boards. Previously, we did `1 + 2 * board_count` queries:: - 1 query to get the list of board records - 1 query per board to get its total count - 1 query per board to get its cover image Then, on the frontend, we made two additional network requests to get each board's counts: - 1 request (== 1 SQL query) for image count - 1 request (== 1 SQL query) for asset count All of this information is now retrieved in a single SQL query, and provided via single network request. As part of this change, `BoardRecord` now includes `image_count`, `asset_count` and `cover_image_name`. This makes `BoardDTO` redundant, but removing it is a deeper change...
- Loading branch information
1 parent
5303f48
commit d8c3e56
Showing
5 changed files
with
157 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,8 @@ | ||
from typing import Optional | ||
|
||
from pydantic import Field | ||
|
||
from invokeai.app.services.board_records.board_records_common import BoardRecord | ||
|
||
|
||
# TODO(psyche): BoardDTO is now identical to BoardRecord. We should consider removing it. | ||
class BoardDTO(BoardRecord): | ||
"""Deserialized board record with cover image URL and image count.""" | ||
|
||
cover_image_name: Optional[str] = Field(description="The name of the board's cover image.") | ||
"""The URL of the thumbnail of the most recent image in the board.""" | ||
image_count: int = Field(description="The number of images in the board.") | ||
"""The number of images in the board.""" | ||
|
||
"""Deserialized board record.""" | ||
|
||
def board_record_to_dto(board_record: BoardRecord, cover_image_name: Optional[str], image_count: int) -> BoardDTO: | ||
"""Converts a board record to a board DTO.""" | ||
return BoardDTO( | ||
**board_record.model_dump(exclude={"cover_image_name"}), | ||
cover_image_name=cover_image_name, | ||
image_count=image_count, | ||
) | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.