Skip to content

Add worker to sync sbom_occurrences.archived

What does this MR do and why?

Adds a worker which responds to Projects::ProjectArchivedEvent and updates the relevant column on the sbom_occurrences table. This column is a denormalization which we are adding in order to remove a subquery when fetching the dependency list index.

Relates to: #437636 (closed)

SQL Queries

Update: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/26156/commands/82265

UPDATE sbom_occurrences
SET
    archived = TRUE
WHERE
    sbom_occurrences.project_id = 278964 AND
    sbom_occurrences.id >= 3469759181 AND
    sbom_occurrences.id < 3469759472;
 ModifyTable on public.sbom_occurrences  (cost=0.56..3.58 rows=0 width=0) (actual time=107.988..107.989 rows=0 loops=1)
   Buffers: shared hit=6518 read=2042 dirtied=526 written=1
   I/O Timings: read=81.995 write=0.000
   ->  Index Scan using index_sbom_occurrences_on_project_id_and_id on public.sbom_occurrences  (cost=0.56..3.58 rows=1 width=7) (actual time=0.953..11.134 rows=99 loops=1)
         Index Cond: ((sbom_occurrences.project_id = 278964) AND (sbom_occurrences.id >= '3469759181'::bigint) AND (sbom_occurrences.id < '3469759472'::bigint))
         Buffers: shared hit=22 read=251 dirtied=158
         I/O Timings: read=9.948 write=0.000
Time: 110.555 ms
  - planning: 2.500 ms
  - execution: 108.055 ms
    - I/O read: 81.995 ms
    - I/O write: 0.000 ms

Shared buffers:
  - hits: 6518 (~50.90 MiB) from the buffer pool
  - reads: 2042 (~16.00 MiB) from the OS file cache, including disk I/O
  - dirtied: 526 (~4.10 MiB)
  - writes: 1 (~8.00 KiB)

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Restart rails-background-jobs since it loves to stop working: gdk restart rails-background-jobs
  2. Start the rails console: bundle exec rails c
  3. Enable the feature flag: Feature.enable(:sync_project_archival_status_to_sbom_occurrences)
  4. Find a project with dependencies: project = Sbom::Occurrence.last.project
  5. Check the archived column, it should be false: project.sbom_occurrences.first.archived
  6. Archive the project: Projects::UpdateService.new(project, User.first, { archived: true }).execute
  7. Check archived status again, it should be true: project.sbom_occurrences.reload.first.archived
Edited by Brian Williams

Merge request reports