Skip to content

Commit

Permalink
cache fixes - problems expected
Browse files Browse the repository at this point in the history
  • Loading branch information
leftmove committed Feb 1, 2025
1 parent 87ed985 commit 31aecbf
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
14 changes: 7 additions & 7 deletions backend/routers/filer.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ async def break_filer(cik: str):
report_error(cik, Exception("Filer is broken but has forms."))


@cache(24)
@router.get("/search", tags=["filers"], status_code=200)
@cache(24)
async def search_filers(q: str, limit: int = 4):
hits = await search_companies(q, limit=limit, filter="thirteen_f = true")

Expand Down Expand Up @@ -490,8 +490,8 @@ async def estimate(cik: str):
raise HTTPException(500, detail="Error fetching time estimation.")


@cache(1 / 6)
@router.get("/info", tags=["filers"], status_code=200)
@cache(1 / 6)
async def filer_info(cik: str):
filer = database.find_filer(cik, {"_id": 0, "stocks": 0})
if filer is None:
Expand Down Expand Up @@ -548,8 +548,8 @@ def convert_keys(obj):
} # Change later


@cache(24)
@router.get("/preview", tags=["filers"], status_code=200)
@cache(24)
async def filer_preview(cik: str, holding_count: int = 5):

if holding_count > 10:
Expand Down Expand Up @@ -758,8 +758,8 @@ def get_sample_filers():
return final_list


@cache(24)
@router.get("/record", tags=["filers", "records"], status_code=200)
@cache(24)
async def record(cik: str):
filer = database.find_filer(cik, {"_id": 1})
if filer is None:
Expand Down Expand Up @@ -811,8 +811,8 @@ async def record_csv(cik: str, headers: str = None):
)


@cache(24)
@router.get("/record/timeseries", tags=["filers", "records"], status_code=200)
@cache(24)
async def partial_record(cik: str, time: float):
filer = database.find_filer(cik, {"stocks": 1, "tickers": 1, "name": 1})
if not filer:
Expand Down Expand Up @@ -894,8 +894,8 @@ async def partial_record(cik: str, time: float):
top_cik_list = json.load(f)


@cache(24)
@router.get("/top", status_code=200)
@cache(24)
async def top_ciks():
try:
filers_sorted = analysis.sort_and_format(top_cik_list)
Expand All @@ -911,8 +911,8 @@ async def top_ciks():
popular_cik_list = json.load(f)


@cache(24)
@router.get("/searched", status_code=200)
@cache(24)
async def popular_ciks():
try:
filers_sorted = analysis.sort_and_format(popular_cik_list)
Expand Down
8 changes: 4 additions & 4 deletions backend/routers/filing.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ def update_filing(
return {"description": "Filing update started."}


@cache(24)
@router.get("/record", tags=["filers", "filing", "records"], status_code=200)
@cache(24)
async def record_filing(cik: str, access_number):
filer = database.find_filer(cik, {"_id": 1})
if filer is None:
Expand All @@ -127,8 +127,8 @@ async def record_filing(cik: str, access_number):
)


@cache(24)
@router.get("/recordcsv", tags=["filers", "filing", "records"], status_code=200)
@cache(24)
async def record_filing_csv(cik: str, access_number: str, headers: str = None):
filer = database.find_filer(cik, {"_id": 1})
if filer is None:
Expand Down Expand Up @@ -165,8 +165,8 @@ async def record_filing_csv(cik: str, access_number: str, headers: str = None):
)


@cache(2)
@router.get("/filer", status_code=200)
@cache(2)
async def filings_info(cik: str):
pipeline = [
{"$match": {"cik": cik, "form": {"$in": database.holding_forms}}},
Expand All @@ -180,8 +180,8 @@ async def filings_info(cik: str):
return {"filings": filings}


@cache(2)
@router.get("/info", status_code=200)
@cache(2)
async def filing_info(cik: str, access_number: str, include_filer: bool = False):
filing = database.find_filing(cik, access_number, {"_id": 0, "cik": 0, "stocks": 0})
if filing is None:
Expand Down
8 changes: 4 additions & 4 deletions backend/routers/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@
top_cik_list = filer.top_cik_list


@cache(24)
@router.get("/", status_code=200)
@cache(24)
async def info():
return {"description": "Hello World!"}


@cache
@router.get("/undefined", status_code=200)
@cache
async def info_undefined():
return {"description": "Hello World!"}


@cache(4)
@router.get("/health", status_code=200)
@cache(4)
async def health():
health_checks = []

Expand Down Expand Up @@ -213,7 +213,7 @@ async def repair_all_filers(
# return {"description": "Hello World!"}


@cache
@router.get("/favicon.ico", status_code=200)
@cache
async def favicon():
return FileResponse(f"{cwd}/static/favicon.ico")
3 changes: 1 addition & 2 deletions backend/routers/lib/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ async def wrapped(*args, **kwargs):
expire_time = 60 * 60 * hours
store.setex(key, expire_time, value_json)
else:
value_json = result.decode("utf-8")
value = json.loads(value_json)
value = json.loads(result)

return value

Expand Down
8 changes: 4 additions & 4 deletions backend/routers/stocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class Cusip(BaseModel):
cusip: list


@cache
@router.get("/query", tags=["stocks"], status_code=200)
@cache
async def query_stocks(cik: str, background: BackgroundTasks):
if cik:
filer = database.search_filer(cik, {"stocks.cusip": 1})
Expand All @@ -39,8 +39,8 @@ async def query_stocks(cik: str, background: BackgroundTasks):
return {"description": "Stocks started updating."}


@cache
@router.get("/filer", tags=["stocks", "filers"], status_code=200)
@cache
async def stock_filer(
cik: str,
limit: int,
Expand Down Expand Up @@ -77,8 +77,8 @@ async def stock_filer(
)


@cache
@router.get("/filing", tags=["stocks", "filings"], status_code=200)
@cache
async def stock_filing(
cik: str,
access_number: str,
Expand Down Expand Up @@ -128,8 +128,8 @@ async def stock_filing(
)


@cache(4)
@router.get("/timeseries", tags=["stocks", "filers"], status_code=200)
@cache(4)
async def stock_timeseries(cik: str, time: float):
filer = database.search_filer(cik, {"stocks.cusip": 1})
if not filer:
Expand Down

0 comments on commit 31aecbf

Please sign in to comment.