mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-29 19:36:20 -05:00
Adding Ebook.find_by_paths to speed up searches.
This commit is contained in:
parent
d8c166379b
commit
3266b6c8b8
2 changed files with 10 additions and 5 deletions
|
|
@ -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`."""
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue