Skip to content

Commit

Permalink
simple cache
Browse files Browse the repository at this point in the history
  • Loading branch information
gleasonw committed Oct 7, 2023
1 parent 975765f commit d791dd3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,9 @@ class Series(BaseModel):
name: str


series_cache: Dict[str, Series] = {}


@app.get("/api/series")
async def get(
term: str,
Expand All @@ -679,6 +682,9 @@ async def get(
source: Literal["livres", "presse", "lemonde"] = "presse",
link_term: Optional[str] = None,
) -> Series:
key = f"{term}-{start_date}-{end_date}-{grouping}-{source}-{link_term}"
if key in series_cache:
return series_cache[key]
debut = start_date or 1789
fin = end_date or 1950
if link_term:
Expand Down Expand Up @@ -738,10 +744,12 @@ def get_unix_timestamp(row) -> int:
lambda row: (get_unix_timestamp(row), row["ratio"]), axis=1
).tolist()

return Series(
series = Series(
data=data,
name=term,
)
series_cache[key] = series
return series


async def fetch_series_dataframe(url: str, params: Dict):
Expand Down

0 comments on commit d791dd3

Please sign in to comment.