feat: warm up cache on app startup for fast first page load
All checks were successful
Build and Push / build (push) Successful in 8s
All checks were successful
Build and Push / build (push) Successful in 8s
Pre-fetches all 4 cached datasets (attendance, juniors, payments, exceptions) at module load time so the first request doesn't block on Google API calls. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
17
app.py
17
app.py
@@ -55,7 +55,24 @@ def get_month_labels(sorted_months, merged_months):
|
||||
labels[m] = dt.strftime("%b %Y")
|
||||
return labels
|
||||
|
||||
def warmup_cache():
|
||||
"""Pre-fetch all cached data so first request is fast."""
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.info("Warming up cache...")
|
||||
credentials_path = CREDENTIALS_PATH
|
||||
|
||||
get_cached_data("attendance_regular", ATTENDANCE_SHEET_ID, get_members_with_fees)
|
||||
get_cached_data("attendance_juniors", ATTENDANCE_SHEET_ID, get_junior_members_with_fees)
|
||||
get_cached_data("payments_transactions", PAYMENTS_SHEET_ID, fetch_sheet_data, PAYMENTS_SHEET_ID, credentials_path)
|
||||
get_cached_data("exceptions_dict", PAYMENTS_SHEET_ID, fetch_exceptions,
|
||||
PAYMENTS_SHEET_ID, credentials_path,
|
||||
serialize=lambda d: [[list(k), v] for k, v in d.items()],
|
||||
deserialize=lambda c: {tuple(k): v for k, v in c},
|
||||
)
|
||||
logger.info("Cache warmup complete.")
|
||||
|
||||
app = Flask(__name__)
|
||||
warmup_cache()
|
||||
|
||||
@app.before_request
|
||||
def start_timer():
|
||||
|
||||
Reference in New Issue
Block a user