tidy(item_storage): remove unused list and search methods

This commit is contained in:
psychedelicious
2024-01-31 22:23:33 +11:00
parent 2965357d99
commit 59279851a3
4 changed files with 0 additions and 149 deletions

View File

@ -3,8 +3,6 @@ from typing import Callable, Generic, TypeVar
from pydantic import BaseModel
from invokeai.app.services.shared.pagination import PaginatedResults
T = TypeVar("T", bound=BaseModel)
@ -35,15 +33,6 @@ class ItemStorageABC(ABC, Generic[T]):
"""Deletes the item"""
pass
@abstractmethod
def list(self, page: int = 0, per_page: int = 10) -> PaginatedResults[T]:
"""Gets a paginated list of items"""
pass
@abstractmethod
def search(self, query: str, page: int = 0, per_page: int = 10) -> PaginatedResults[T]:
pass
def on_changed(self, on_changed: Callable[[T], None]) -> None:
"""Register a callback for when an item is changed"""
self._on_changed_callbacks.append(on_changed)

View File

@ -3,7 +3,6 @@ from typing import Generic, Optional, TypeVar
from pydantic import BaseModel
from invokeai.app.services.item_storage.item_storage_base import ItemStorageABC
from invokeai.app.services.shared.pagination import PaginatedResults
T = TypeVar("T", bound=BaseModel)
@ -27,16 +26,3 @@ class ItemStorageMemory(ItemStorageABC, Generic[T]):
self._on_deleted(item_id)
except KeyError:
pass
def list(self, page: int = 0, per_page: int = 10) -> PaginatedResults[T]:
# TODO: actually paginate?
return PaginatedResults(
items=list(self._items.values()), page=page, per_page=per_page, pages=1, total=len(self._items)
)
def search(self, query: str, page: int = 0, per_page: int = 10) -> PaginatedResults[T]:
# TODO: actually paginate?
# TODO: actually search?
return PaginatedResults(
items=list(self._items.values()), page=page, per_page=per_page, pages=1, total=len(self._items)
)

View File

@ -4,7 +4,6 @@ from typing import Generic, Optional, TypeVar, get_args
from pydantic import BaseModel, TypeAdapter
from invokeai.app.services.shared.pagination import PaginatedResults
from invokeai.app.services.shared.sqlite.sqlite_database import SqliteDatabase
from .item_storage_base import ItemStorageABC
@ -89,46 +88,3 @@ class SqliteItemStorage(ItemStorageABC, Generic[T]):
finally:
self._lock.release()
self._on_deleted(id)
def list(self, page: int = 0, per_page: int = 10) -> PaginatedResults[T]:
try:
self._lock.acquire()
self._cursor.execute(
f"""SELECT item FROM {self._table_name} LIMIT ? OFFSET ?;""",
(per_page, page * per_page),
)
result = self._cursor.fetchall()
items = [self._parse_item(r[0]) for r in result]
self._cursor.execute(f"""SELECT count(*) FROM {self._table_name};""")
count = self._cursor.fetchone()[0]
finally:
self._lock.release()
pageCount = int(count / per_page) + 1
return PaginatedResults[T](items=items, page=page, pages=pageCount, per_page=per_page, total=count)
def search(self, query: str, page: int = 0, per_page: int = 10) -> PaginatedResults[T]:
try:
self._lock.acquire()
self._cursor.execute(
f"""SELECT item FROM {self._table_name} WHERE item LIKE ? LIMIT ? OFFSET ?;""",
(f"%{query}%", per_page, page * per_page),
)
result = self._cursor.fetchall()
items = [self._parse_item(r[0]) for r in result]
self._cursor.execute(
f"""SELECT count(*) FROM {self._table_name} WHERE item LIKE ?;""",
(f"%{query}%",),
)
count = self._cursor.fetchone()[0]
finally:
self._lock.release()
pageCount = int(count / per_page) + 1
return PaginatedResults[T](items=items, page=page, pages=pageCount, per_page=per_page, total=count)