From 35da875d105299159bd5546a90771748e3c21141 Mon Sep 17 00:00:00 2001 From: yuuki <> Date: Sun, 6 Apr 2025 08:33:43 +0000 Subject: [PATCH] =?UTF-8?q?=E3=83=9A=E3=83=BC=E3=82=B8=E3=82=B5=E3=82=A4?= =?UTF-8?q?=E3=82=BA=E3=82=92ctx=E3=81=AB=E3=81=BE=E3=81=A8=E3=82=81?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 9161e20..0a6accf 100644 --- a/app.py +++ b/app.py @@ -84,6 +84,8 @@ async def lifespan(app: FastAPI): #ctx["mongo_client"].litey.notes.create_index("id", unique=True) ctx["mongo_client"].litey.ngs.create_index("word", unique=True) + ctx["page_size"] = 100 + pprint(ctx) redis_uri = environ.get("REDIS_URI", "redis://127.0.0.1:6379/") @@ -135,11 +137,11 @@ def get_ip(req: Request) -> str: return req.headers.get("CF-Connecting-IP") or req.headers.get("X-Forwarded-For") or req.client.host def get_max_page() -> int: - return ceil(ctx["mongo_client"].litey.notes.count_documents({}) / 50) + return ceil(ctx["mongo_client"].litey.notes.count_documents({}) / ctx["page_size"]) def get_litey_notes(id: str = None, page: int = 0) -> List[dict]: if not id: - cursor = ctx["mongo_client"].litey.notes.find({}, { "_id": False }).sort("date", DESCENDING).skip(page * 50).limit(50) + cursor = ctx["mongo_client"].litey.notes.find({}, { "_id": False }).sort("date", DESCENDING).skip(page * ctx["page_size"]).limit(ctx["page_size"]) return list(cursor) return ctx["mongo_client"].litey.notes.find_one({ "id": id }, { "_id": False })