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

Lower amount of DB connections #547

Merged
merged 10 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion prediction_market_agent_tooling/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class APIKeys(BaseSettings):

SQLALCHEMY_DB_URL: t.Optional[SecretStr] = None

ENABLE_CACHE: bool = True
ENABLE_CACHE: bool = False
Copy link
Contributor Author

Choose a reason for hiding this comment

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

By default set to False, to not error out cached functions if postgres access isn't set.

CACHE_DIR: str = "./.cache"

@property
Expand Down
4 changes: 3 additions & 1 deletion prediction_market_agent_tooling/tools/caches/db_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
# Use custom json serializer and deserializer, because otherwise, for example `datetime` serialization would fail.
json_serializer=json_serializer,
json_deserializer=json_deserializer,
pool_size=1,
)

# Create table if it doesn't exist
Expand Down Expand Up @@ -195,7 +196,7 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
)

# If postgres access was specified, save it.
if engine is not None and (cache_none or computed_result is not None):
if cache_none or computed_result is not None:
cache_entry = FunctionCache(
function_name=function_name,
full_function_name=full_function_name,
Expand All @@ -209,6 +210,7 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
session.add(cache_entry)
session.commit()

engine.dispose()
return computed_result

return cast(FunctionT, wrapper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ class RelevantNewsCacheModel(SQLModel, table=True):
class RelevantNewsResponseCache:
def __init__(self, sqlalchemy_db_url: str | None = None):
self.engine = create_engine(
sqlalchemy_db_url
if sqlalchemy_db_url
else APIKeys().sqlalchemy_db_url.get_secret_value()
(
sqlalchemy_db_url
if sqlalchemy_db_url
else APIKeys().sqlalchemy_db_url.get_secret_value()
),
pool_size=1,
)
self._initialize_db()

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "prediction-market-agent-tooling"
version = "0.56.1"
version = "0.56.2"
description = "Tools to benchmark, deploy and monitor prediction market agents."
authors = ["Gnosis"]
readme = "README.md"
Expand Down
Loading