Skip to content

Commit f2250a7

Browse files
committed
fix: user notifications about packages being triggered several times
1 parent 8f02f19 commit f2250a7

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/shared/channels.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ class ContainerChannel(TriggerChannel):
4343
@dataclass
4444
class CVEDerivationClusterProposalChannel(TriggerChannel):
4545
model = CVEDerivationClusterProposal
46-
# We don't need to lock notifications.
47-
# If we are caching twice the same proposal, we will just replace it.
48-
lock_notifications = False
46+
# CVEDerivationClusterProposal aka suggestions, may generate notifications to users, we don't want to issue duplicated suggestions
47+
lock_notifications = True
4948

5049

5150
@dataclass
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 4.2.24 on 2025-10-30 16:56
2+
3+
from django.db import migrations
4+
import pgtrigger.compiler
5+
import pgtrigger.migrations
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('shared', '0057_nixderivation_shared_nixd_attribu_5fcca7_btree'),
12+
]
13+
14+
operations = [
15+
pgtrigger.migrations.RemoveTrigger(
16+
model_name='cvederivationclusterproposal',
17+
name='pgpubsub_8c7ef',
18+
),
19+
pgtrigger.migrations.AddTrigger(
20+
model_name='cvederivationclusterproposal',
21+
trigger=pgtrigger.compiler.Trigger(name='pgpubsub_8c7ef', sql=pgtrigger.compiler.UpsertTriggerSql(declare='DECLARE payload JSONB; notification_context_text TEXT;', func='\n \n payload := \'{"app": "shared", "model": "CVEDerivationClusterProposal"}\'::jsonb;\n payload := jsonb_insert(payload, \'{old}\', COALESCE(to_jsonb(OLD), \'null\'));\n payload := jsonb_insert(payload, \'{new}\', COALESCE(to_jsonb(NEW), \'null\'));\n SELECT current_setting(\'pgpubsub.notification_context\', True) INTO notification_context_text;\n IF COALESCE(notification_context_text, \'\') = \'\' THEN\n notification_context_text := \'{}\';\n END IF;\n payload := jsonb_insert(payload, \'{context}\', notification_context_text::jsonb);\n \n \n INSERT INTO pgpubsub_notification (channel, payload)\n VALUES (\'pgpubsub_8c7ef\', payload);\n \n perform pg_notify(\'pgpubsub_8c7ef\', payload::text);\n RETURN NEW;\n ', hash='f992274d71c90db51227a6220854697b1f77b60e', operation='INSERT', pgid='pgtrigger_pgpubsub_8c7ef_29d5d', table='shared_cvederivationclusterproposal', when='AFTER')),
22+
),
23+
]

0 commit comments

Comments
 (0)