Adding Ebook.find_by_paths to speed up searches.

This commit is contained in:
Roland 2022-12-16 10:14:55 -07:00
parent d8c166379b
commit 3266b6c8b8
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
2 changed files with 10 additions and 5 deletions

View file

@ -163,6 +163,15 @@ class EBook(ModelHelper, Base):
if self.cover_file:
yield self.cover_file
@staticmethod
def find_by_path(path, session) -> Base:
return session.query(EBook).filter(EBook.ebook_path == path).one_or_none()
@staticmethod
def find_by_paths(paths: List[pathlib.Path], session) -> List:
ebooks = list(session.query(EBook).filter(EBook.ebook_path.in_(paths)))
return ebooks
def __json__(self):
d = dict(
cover_path=self.cover_path,
@ -192,10 +201,6 @@ class EBook(ModelHelper, Base):
logger.warning(f'Unable to generate cover for {self.ebook_path}')
@staticmethod
def find_by_path(path, session) -> Base:
return session.query(EBook).filter(EBook.ebook_path == path).one_or_none()
def model_ebook(ebook: EBook, files: List[File]) -> EBook:
"""Creates an EBook model based off a File. Searches for it's cover in the provided `files`."""

View file

@ -25,7 +25,7 @@ class File(ModelHelper, Base):
full_stem = Column(String) # f'{directory}/{stem}'
idempotency = Column(TZDateTime, default=lambda: now())
indexed = Column(Boolean, default=False)
mimetype = Column(String) # Gotten by python-magic or file command.
mimetype = Column(String) # wrolpi.files.lib.get_mimetype
model = Column(String) # Filled out by the modeler. Will be the table name (video, archive, etc.).
modification_datetime = Column(TZDateTime)
size = Column(Integer)