Compare commits
No commits in common. "35da875d105299159bd5546a90771748e3c21141" and "7bb39646bea694ba9bf1128e7e137192e97efd32" have entirely different histories.
35da875d10
...
7bb39646be
2 changed files with 5 additions and 7 deletions
6
app.py
6
app.py
|
@ -84,8 +84,6 @@ async def lifespan(app: FastAPI):
|
||||||
#ctx["mongo_client"].litey.notes.create_index("id", unique=True)
|
#ctx["mongo_client"].litey.notes.create_index("id", unique=True)
|
||||||
ctx["mongo_client"].litey.ngs.create_index("word", unique=True)
|
ctx["mongo_client"].litey.ngs.create_index("word", unique=True)
|
||||||
|
|
||||||
ctx["page_size"] = 100
|
|
||||||
|
|
||||||
pprint(ctx)
|
pprint(ctx)
|
||||||
|
|
||||||
redis_uri = environ.get("REDIS_URI", "redis://127.0.0.1:6379/")
|
redis_uri = environ.get("REDIS_URI", "redis://127.0.0.1:6379/")
|
||||||
|
@ -137,11 +135,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
|
return req.headers.get("CF-Connecting-IP") or req.headers.get("X-Forwarded-For") or req.client.host
|
||||||
|
|
||||||
def get_max_page() -> int:
|
def get_max_page() -> int:
|
||||||
return ceil(ctx["mongo_client"].litey.notes.count_documents({}) / ctx["page_size"])
|
return ceil(ctx["mongo_client"].litey.notes.count_documents({}) / 50)
|
||||||
|
|
||||||
def get_litey_notes(id: str = None, page: int = 0) -> List[dict]:
|
def get_litey_notes(id: str = None, page: int = 0) -> List[dict]:
|
||||||
if not id:
|
if not id:
|
||||||
cursor = ctx["mongo_client"].litey.notes.find({}, { "_id": False }).sort("date", DESCENDING).skip(page * ctx["page_size"]).limit(ctx["page_size"])
|
cursor = ctx["mongo_client"].litey.notes.find({}, { "_id": False }).sort("date", DESCENDING).skip(page * 50).limit(50)
|
||||||
return list(cursor)
|
return list(cursor)
|
||||||
|
|
||||||
return ctx["mongo_client"].litey.notes.find_one({ "id": id }, { "_id": False })
|
return ctx["mongo_client"].litey.notes.find_one({ "id": id }, { "_id": False })
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
requests==2.32.3
|
requests==2.32.3
|
||||||
fastapi[standard]==0.115.12
|
fastapi[standard]==0.115.8
|
||||||
pymongo==4.11.3
|
pymongo==4.11
|
||||||
Jinja2==3.1.6
|
Jinja2==3.1.5
|
||||||
fastapi-limiter==0.1.6
|
fastapi-limiter==0.1.6
|
||||||
|
|
Loading…
Add table
Reference in a new issue