Skip to content

Commit 8902dbd

Browse files
dkrizanclaude
andcommitted
fix: restrict DELETE scope in removeDuplicityDescribingEntities
The DELETE query in BatchJobActivityFinalizer.removeDuplicityDescribingEntities was missing an activity_revision_id filter on the outer WHERE clause. This caused a full sequential scan of the entire activity_describing_entity table (5.5 GB in production) on every batch job completion, making the query take ~9 seconds instead of <1ms. Additionally, the missing filter meant the DELETE could affect rows from unrelated historical activity revisions that happened to share the same (entity_class, entity_id) as entities in the batch being merged, silently corrupting activity history data. Fix: add (activity_revision_id in (:revisionIds) or activity_revision_id = :activityRevisionIdToMergeInto) as the leading predicate on the outer DELETE, restricting it to only the chunk revisions being merged. This allows the existing index on (activity_revision_id, entity_class, entity_id) to be used. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d8baa63 commit 8902dbd

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

backend/data/src/main/kotlin/io/tolgee/batch/BatchJobActivityFinalizer.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ class BatchJobActivityFinalizer(
171171
.createNativeQuery(
172172
"""
173173
delete from activity_describing_entity
174-
where (entity_class, entity_id) in
174+
where (activity_revision_id in (:revisionIds) or activity_revision_id = :activityRevisionIdToMergeInto)
175+
and (entity_class, entity_id) in
175176
(select entity_class, entity_id
176177
from activity_describing_entity
177178
where activity_revision_id in (:revisionIds)

0 commit comments

Comments
 (0)