Skip to content

Commit 3eb0e2b

Browse files
JakobMiesnerkpsherva
authored andcommitted
stats: record change ids only contain user_id when it is not None
1 parent b01a02a commit 3eb0e2b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

invenio_app_ils/stats/processors.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ def add_record_change_ids(doc):
1313
"""Add unique_id and aggregation_id to the doc."""
1414

1515
# We use this field to group by during aggregation.
16-
# e.g. the count of created eitems by a user with id 7 is tracked under eitmid__insert__None.
17-
doc["aggregation_id"] = f"{doc['pid_type']}__{doc['method']}__{doc['user_id']}"
16+
# e.g. the count of created eitems by a user with id 7 is tracked under eitmid__insert__7.
17+
doc["aggregation_id"] = f"{doc['pid_type']}__{doc['method']}"
1818

1919
# unique_id identifies each individual event and is used by invenio-stats.
2020
# It automatically deduplicates events from the same second that have the same unique_id.
2121
# Including the pid_value ensures distinctness between events,
2222
# even when multiple records are updated within the same second.
2323
# e.g. during the importer in cds-ils where many eitems are created in bulk.
24-
doc["unique_id"] = (
25-
f"{doc['pid_value']}__{doc['pid_type']}__{doc['method']}__{doc['user_id']}"
26-
)
24+
doc["unique_id"] = f"{doc['pid_value']}__{doc['pid_type']}__{doc['method']}"
25+
26+
if doc["user_id"]:
27+
doc["aggregation_id"] += f"__{doc['user_id']}"
28+
doc["unique_id"] += f"__{doc['user_id']}"
2729

2830
return doc

0 commit comments

Comments
 (0)