-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Description
Problem
Each PDF preview request re-downloads and re-renders the PDF, even for the same page. This is inefficient when users navigate back and forth between pages.
Recommendation
Add a simple LRU cache for rendered pages:
from functools import lru_cache
import hashlib
# Cache key: (user_id, file_path, page, scale, pdf_hash)
@lru_cache(maxsize=100) # Cache last 100 rendered pages
def _render_pdf_page_cached(cache_key: tuple) -> tuple[bytes, int]:
user_id, file_path, page_num, scale, pdf_hash = cache_key
# Actual rendering logic here
...
# In get_pdf_preview():
pdf_hash = hashlib.sha256(pdf_bytes).hexdigest()[:16]
cache_key = (user_id, file_path, page_num, scale, pdf_hash)
png_bytes, total_pages = _render_pdf_page_cached(cache_key)Benefit: Significantly reduces CPU load when users navigate between pages.
Trade-off: Memory usage (100 pages × ~500KB ≈ 50MB is reasonable).
Location
nextcloud_mcp_server/api/visualization.py
Priority
Nice to have - Performance optimization
Parent Issue
Part of #502
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels