Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use latest PMAT (mostly caching stuff) #18

Merged
merged 4 commits into from
Nov 6, 2024
Merged

Conversation

kongzii
Copy link
Collaborator

@kongzii kongzii commented Oct 30, 2024

No description provided.

@kongzii kongzii marked this pull request as ready for review October 31, 2024 13:56


@db_cache(max_age=timedelta(days=3))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that in APIs, it makes sense to observe only the first call -- no benefit in observing every call from potentially many many users on frontend. That's why the db_cache decorator is above observe decorator.

@@ -56,17 +36,19 @@ def market_insights(market_id: HexAddress) -> MarketInsightsResponse:
raise fastapi.HTTPException(
status_code=404, detail=f"Market with id `{market_id}` not found."
)
except Exception as e:
logger.error(f"Failed to fetch market for `{market_id}`: {e}")
raise fastapi.HTTPException(status_code=500)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little simplification thanks to this -- on unhandled errors, APIs usually raise 500 instead of catching it and returning a dummy response.

)
except Exception as e:
logger.error(f"Failed to get tavily_response for market `{market_id}`: {e}")
tavily_response = None
raise fastapi.HTTPException(status_code=500)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to inform the user that the market wasn't found? So probably raise a 404 (or any 4xx)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but that is already handled above:

Screenshot by Dropbox Capture

These 500 codes should be raised only if there are unseemed errors/bugs.

@kongzii kongzii merged commit f53d72f into main Nov 6, 2024
7 checks passed
@kongzii kongzii deleted the peter/latest-pmat-cache branch November 6, 2024 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants