Skip to content

Commit

Permalink
avoid using id
Browse files Browse the repository at this point in the history
  • Loading branch information
petrjasek committed Jan 8, 2025
1 parent 72edb98 commit 1c890fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 7 additions & 9 deletions server/planning/events/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,15 @@ def is_event_updated(new_item: Event, old_item: Event) -> bool:
return False


def get_user_updated_keys(id: str) -> set[str]:
# Placeholder function definition
# Replace this with the actual implementation
def get_user_updated_keys(event_id: str) -> set[str]:
history_service = get_resource_service("events_history")
updates = history_service.get_by_id(id)
updates = history_service.get_by_id(event_id)
updated_keys = set()
for update in updates:
if not update.get("user_id"):
continue
for key in update.get("update", {}):
updated_keys.add(key)
if update.get("update"):
updated_keys.update(update["update"].keys())
return updated_keys


Expand All @@ -168,17 +166,17 @@ def post_in_mongo(self, docs, **kwargs):
self.on_created(docs)
return ids

def patch_in_mongo(self, id: str, document, original) -> Optional[Dict[str, Any]]:
def patch_in_mongo(self, _id: str, document, original) -> Optional[Dict[str, Any]]:
"""Patch an ingested item onto an existing item locally"""
content_fields = app.config.get("EVENT_INGEST_CONTENT_FIELDS", CONTENT_FIELDS)
updated_keys = get_user_updated_keys(id)
updated_keys = get_user_updated_keys(_id)
for key in updated_keys:
if key in document and key in content_fields and original.get(key):
document[key] = original[key]

set_planning_schedule(document)
update_ingest_on_patch(document, original)
response = self.backend.update_in_mongo(self.datasource, id, document, original)
response = self.backend.update_in_mongo(self.datasource, _id, document, original)
self.on_updated(document, original, from_ingest=True)
return response

Expand Down
4 changes: 2 additions & 2 deletions server/planning/events/events_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def on_update_repetitions(self, updates, event_id, operation):
def on_update_time(self, updates, original):
self.on_item_updated(updates, original, "update_time")

def get_by_id(self, id: str) -> list[EventHistoryRecord]:
records = self.find(where={"event_id": id})
def get_by_id(self, _id: str) -> list[EventHistoryRecord]:
records = self.find(where={"event_id": _id})
return [
{
"event_id": record.get("event_id"),
Expand Down

0 comments on commit 1c890fe

Please sign in to comment.