Skip to content

Commit 10dcb8f

Browse files
committed
feat: wip! wip! wip!
Signed-off-by: Raito Bezarius <[email protected]>
1 parent e360103 commit 10dcb8f

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/website/shared/channels.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from dataclasses import dataclass
22

3-
from pgpubsub.channel import TriggerChannel
3+
from pgpubsub.channel import TriggerChannel, Channel
44

55
from shared.models import NixDerivation
66
from shared.models.cve import Container
@@ -46,3 +46,11 @@ class CVEDerivationClusterProposalChannel(TriggerChannel):
4646
# We don't need to lock notifications.
4747
# If we are caching twice the same proposal, we will just replace it.
4848
lock_notifications = False
49+
50+
@dataclass
51+
class NixEvaluationCompleteChannel(Channel):
52+
evaluation_id: int
53+
# We do not want to want to perform twice attribute path tracking.
54+
# It's expensive and the second time it's the identity mapping we are constructing.
55+
# We may revisit this if needed.
56+
lock_notifications = True

src/website/shared/listeners/nix_evaluation.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
from django.conf import settings
1414
from django.db.models import Avg
1515

16-
from shared.channels import NixEvaluationChannel
16+
from shared.channels import NixEvaluationChannel, NixEvaluationCompleteChannel
1717
from shared.evaluation import (
1818
SyncBatchAttributeIngester,
1919
parse_evaluation_result,
2020
)
2121
from shared.git import GitRepo
2222
from shared.models import NixDerivation, NixEvaluation
23+
from shared.models.linkage import DerivationClusterProposalLink
2324

2425
logger = logging.getLogger(__name__)
2526

@@ -240,6 +241,14 @@ async def evaluation_entrypoint(
240241
state=NixEvaluation.EvaluationState.COMPLETED,
241242
elapsed=elapsed,
242243
)
244+
245+
# Notify that we have a new evaluation ready and
246+
# any listeners should now proceed to an global update of old derivations
247+
# via attribute path.
248+
pgpubsub.notify(
249+
'shared.channels.NixEvaluationCompleteChannel',
250+
model_id=evaluation.pk,
251+
)
243252
except Exception as e:
244253
elapsed = time.time() - start
245254
logger.exception(
@@ -279,3 +288,29 @@ def run_evaluation_job(old: NixEvaluation, new: NixEvaluation) -> None:
279288
new,
280289
)
281290
)
291+
292+
def swap_derivations_based_on_attrpath(derivation_ids: list[int]):
293+
new_derivation_id_subquery = """
294+
SELECT new_derivation.id
295+
FROM shared_nixderivation AS old_derivation
296+
JOIN shared_nixderivation AS new_derivation
297+
ON old_derivation.attribute = new_derivation.attribute
298+
WHERE
299+
DerivationClusterProposalLink.derivation_id = old_derivation.id
300+
AND new_derivation.parent_evaluation_id = %s
301+
"""
302+
303+
304+
@pgpubsub.listener(NixEvaluationCompleteChannel)
305+
def run_attribute_tracking_job(evaluation_id: int) -> None:
306+
# Our objective is to update:
307+
# - pending suggestions
308+
# - accepted suggestions
309+
# TODO: in the future, we should not update "mitigated" issues so we can easily revisit _which_ derivation was the last one.
310+
311+
for proposal in CVEDerivationClusterProposal.objects.filter(status__in=(CVEDerivationClusterProposal.Status.PENDING, CVEDerivationClusterProposal.ACCEPTED)).iterator():
312+
# Update all proposal
313+
swap_derivations_based_on_attrpath()
314+
315+
# TODO: Update all cached variants as well.
316+

0 commit comments

Comments
 (0)