Skip to content

Commit

Permalink
Lower amount of DB connections (#547)
Browse files Browse the repository at this point in the history
* Single shared engine instance

* fixes

* revert accidental bump

* fix pickle in github ci

* fiiiix

* fix loguru

* revert

* ah

* ah2

* revert
  • Loading branch information
kongzii authored Nov 11, 2024
1 parent dfa90ca commit 3c7e09a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
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
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

0 comments on commit 3c7e09a

Please sign in to comment.