Skip to content

Commit 6d7cb07

Browse files
committed
⚡️ Optionally don't dehydrate entity payloads
1 parent 8315c34 commit 6d7cb07

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

openaleph_procrastinate/model.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
from pathlib import Path
44
from typing import Any, ContextManager, Generator, Iterable, Literal, Self, TypeAlias
55

6-
from anystore.logging import BoundLogger, get_logger
6+
from anystore.logging import get_logger
77
from anystore.store.virtual import VirtualIO
88
from anystore.util import clean_dict
99
from banal import ensure_dict
1010
from followthemoney import model
1111
from followthemoney.proxy import EntityProxy
1212
from ftmq.store.fragments.loader import BulkLoader
1313
from pydantic import BaseModel, ConfigDict, computed_field
14+
from structlog.stdlib import BoundLogger
1415

1516
from openaleph_procrastinate import helpers
1617
from openaleph_procrastinate.app import App, run_sync_worker
@@ -139,8 +140,13 @@ def get_entities(self) -> Generator[EntityProxy, None, None]:
139140
def load_entities(self: Self) -> Generator[EntityProxy, None, None]:
140141
"""Load the entities from the store to refresh it to the latest data"""
141142
assert "entities" in self.payload, "No entities in payload"
142-
for data in self.payload["entities"]:
143-
yield helpers.load_entity(self.dataset, data["id"])
143+
144+
# if not dehydrating, just get the payload data:
145+
if not settings.procrastinate_dehydrate_entities:
146+
yield from self.get_entities()
147+
else:
148+
for data in self.payload["entities"]:
149+
yield helpers.load_entity(self.dataset, data["id"])
144150

145151
# Helpers for file jobs that access the servicelayer archive
146152

@@ -179,7 +185,7 @@ def from_entities(
179185
queue: str,
180186
task: str,
181187
entities: Iterable[EntityProxy],
182-
dehydrate: bool | None = False,
188+
dehydrate: bool = settings.procrastinate_dehydrate_entities,
183189
**context: Any,
184190
) -> Self:
185191
"""

openaleph_procrastinate/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ class OpenAlephSettings(BaseSettings):
224224
)
225225
"""FollowTheMoney Fragments store uri"""
226226

227+
procrastinate_dehydrate_entities: bool = True
228+
"""Dehydrate entity in job payload, jobs need to re-fetch entity from store"""
229+
227230
@property
228231
def in_memory_db(self) -> bool:
229232
return self.procrastinate_db_uri.startswith("memory:")

0 commit comments

Comments
 (0)