Loads the book from the pickle file. Cached so we don't re-read the disk on every click.
(folder_name: str)
| 18 | |
| 19 | @lru_cache(maxsize=10) |
| 20 | def load_book_cached(folder_name: str) -> Optional[Book]: |
| 21 | """ |
| 22 | Loads the book from the pickle file. |
| 23 | Cached so we don't re-read the disk on every click. |
| 24 | """ |
| 25 | file_path = os.path.join(BOOKS_DIR, folder_name, "book.pkl") |
| 26 | if not os.path.exists(file_path): |
| 27 | return None |
| 28 | |
| 29 | try: |
| 30 | with open(file_path, "rb") as f: |
| 31 | book = pickle.load(f) |
| 32 | return book |
| 33 | except Exception as e: |
| 34 | print(f"Error loading book {folder_name}: {e}") |
| 35 | return None |
| 36 | |
| 37 | @app.get("/", response_class=HTMLResponse) |
| 38 | async def library_view(request: Request): |
no outgoing calls
no test coverage detected