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

Make EntityCache per request #45

Merged
merged 1 commit into from
Dec 4, 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
6 changes: 3 additions & 3 deletions featureflags/http/repositories/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ def __init__(
self._db_engine = db_engine
self._graph_engine = graph_engine

self._entity_cache = EntityCache()

async def get_project_version(self, project: str) -> int:
async with self._db_engine.acquire() as conn:
return await select_scalar(
Expand All @@ -99,11 +97,13 @@ async def prepare_project(
Initialize project from request, create/update entities in the database.
"""

entity_cache = EntityCache()

async with self._db_engine.acquire() as conn:
await prepare_flags_project(
request,
conn=conn,
entity_cache=self._entity_cache,
entity_cache=entity_cache,
)

async def load(self, request: PreloadFlagsRequest) -> PreloadFlagsResponse:
Expand Down
4 changes: 2 additions & 2 deletions featureflags/rpc/servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def __init__(
db_engine: aiopg.sa.Engine,
graph_engine: Engine,
) -> None:
self._entity_cache = EntityCache()
self._flag_agg_stats = FlagAggStats()
self._graph_engine = graph_engine
self._db_engine = db_engine
Expand All @@ -45,6 +44,7 @@ async def exchange(self, stream: Stream) -> None:
@debug_cancellation
@track
async def Exchange(self, stream: Stream) -> None: # noqa: N802
entity_cache = EntityCache()
self._tasks.add(asyncio.current_task())
try:
request: service_pb2.ExchangeRequest = await stream.recv_message()
Expand Down Expand Up @@ -74,7 +74,7 @@ async def Exchange(self, stream: Stream) -> None: # noqa: N802
await add_statistics(
request,
conn=conn,
entity_cache=self._entity_cache,
entity_cache=entity_cache,
flag_agg_stats=self._flag_agg_stats,
)
version = await select_scalar(
Expand Down
Loading