Skip to content

Story #2586 :: Task: Wire the Library Maintenance achievement, counting libraries and not versions - #2587

Open
herzog0 wants to merge 1 commit into
teo/2541-source-library-authoringfrom
teo/2541-source-library-maintenance
Open

Story #2586 :: Task: Wire the Library Maintenance achievement, counting libraries and not versions#2587
herzog0 wants to merge 1 commit into
teo/2541-source-library-authoringfrom
teo/2541-source-library-maintenance

Conversation

@herzog0

@herzog0 herzog0 commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Issue: #2586

⚠️ Base branch is teo/2541-source-library-authoring

Summary & Context

Wires the Library Maintenance achievement. The one thing worth reviewing here is the grain:
maintainers are recorded per LibraryVersion, but the badge counts libraries maintained
(1 / 2 / 5 / 10 / 20), so the iterator deduplicates across versions and yields the Library as
the achievement source.

Without that, a maintainer of one library with 40 releases would hold diamond.

  • Figma link: n/a
  • Link to components/page: n/a

Changes

  • _iter_library_maintenance walks LibraryVersion with its maintainers prefetched and yields
    (user, library) once per (user, library) pair, tracking what it has already seen.
  • Registered in BACKFILL_ITERATORS.
  • test_iter_library_maintenance_dedupes_versions - three versions of one library yield exactly
    one pair.
  • test_backfill_library_maintenance - two versions, one grant, one badge.

‼️ Risks & Considerations ‼️

  • The dedup set is held in memory for the whole walk. It is one tuple per (user, library) pair,
    bounded by the number of maintainer relationships, not by the number of versions - a few
    thousand entries at Boost's scale.
  • The source object recorded on the grant is the Library, not the LibraryVersion. This is
    what makes the grant idempotent under unique_automatic_user_achievement_source and what lets
    reconciliation match it. An earlier iteration of this feature recorded versions and had to be
    cleaned up with a data migration; a fresh install never creates those rows.
  • Dropping a maintainer from every version of a library removes the grant on the next
    reconcile, the two-way command, not on a backfill. That is by design.

Screenshots

n/a - no UI.

Peer-review testing steps

The dedup is basically the whole PR, and it is visible on a changelist.

  1. The source is wired. /admin/badges/badge/ - the Maintainer row's Automatic column is a
    tick and its ladder reads 1 / 2 / 5 / 10 / 20.

  2. Make yourself a maintainer of one library, several times over.
    /admin/libraries/libraryversion/, filter by a single library, then open three of its versions
    and add your own user to Maintainers on each.

  3. Backfill. /admin/badges/userachievement/ -> Backfill achievements with Source set to
    Library Maintenance.

  4. Three versions, one grant. Filter that changelist by Achievement: Library Maintenance: you
    have exactly one row, and its Source column links to the library, not to any of the
    three versions. Without the dedup this step is where you would see three. /admin/badges/userbadge/
    shows Maintainer / Bronze; the per-member page (your name, linked from either badge changelist)
    reads one valid grant and 1 to go to Silver.

  5. A second library does move the count. Add yourself to Maintainers on one version of a
    different library and press Backfill again: two grants, and Maintainer / Silver is
    awarded. This is what proves the dedup is per (member, library) and not just "one grant per member".

  6. Removal is a reconcile, and it demotes. Drop yourself from all three versions of the first
    library. Backfill changes nothing. Then Reconcile achievements with Source on Library
    Maintenance
    : the preview reports one removal, Apply, and the Silver row is revoked with
    Count at revocation 1 while Bronze stays held. /admin/badges/achievementsyncrun/ shows the run
    with Removed 1, and the revoked badge's notes name it.

  7. Sanity-check against real data. Backfill All sources on a production copy, then filter
    /admin/badges/userbadge/ to Badge: Maintainer and Rank: Diamond. Every name there must genuinely
    maintain 20 or more libraries - filter /admin/badges/userachievement/ by Achievement: Library
    Maintenance
    , search their email, and count the rows, whose Source links must all be distinct
    libraries. Without the dedup, anyone maintaining a single long-lived library would be sitting in that
    Diamond list, which is the failure this PR exists to prevent.

Self-review Checklist

  • Tag at least one team member from each team to review this PR
  • Link this PR to the related GitHub Project ticket

Backend

  • Black + Ruff clean
  • No new models or migrations
  • Full suite green: 1336 passed / 43 skipped

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 221d087f-a7a8-4ba2-8af9-c58bea91e959

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@herzog0 herzog0 changed the title feat: derive the library maintenance achievement per library maintained Story #2586 :: Task: Wire the Library Maintenance achievement, counting libraries and not versions Aug 6, 2026
@herzog0
herzog0 force-pushed the teo/2541-source-library-maintenance branch from 32fb541 to 07a2b1c Compare August 11, 2026 15:16
@herzog0
herzog0 force-pushed the teo/2541-source-library-maintenance branch from 07a2b1c to d3c392d Compare August 11, 2026 16:48
@herzog0
herzog0 force-pushed the teo/2541-source-library-maintenance branch from d3c392d to 1696c2c Compare August 11, 2026 17:13
@herzog0
herzog0 force-pushed the teo/2541-source-library-maintenance branch from 1696c2c to a253833 Compare August 11, 2026 17:59
@julhoang
julhoang self-requested a review August 12, 2026 21:08

@julhoang julhoang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me, thanks @herzog0 ! I just have 1 nit suggestion below for a test.

Comment on lines +57 to +65
def test_iter_library_maintenance_dedupes_versions(plain_user):
"""Maintaining many versions of one library yields a single pair."""
library = baker.make("libraries.Library")
for _ in range(3):
version = baker.make("libraries.LibraryVersion", library=library)
version.maintainers.add(plain_user)

pairs = list(sources._iter_library_maintenance())
assert pairs == [(plain_user, library)]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit suggestion: Perhaps we can update this test to add another library here, and assert that pairs == [(plain_user, library), (plain_user, another library)] to ensure we can cover that common case as well!

@herzog0
herzog0 force-pushed the teo/2541-source-library-maintenance branch from a253833 to 2703076 Compare August 13, 2026 14:44
@herzog0
herzog0 force-pushed the teo/2541-source-library-maintenance branch from 2703076 to 53d58b6 Compare August 14, 2026 15:26
@herzog0
herzog0 force-pushed the teo/2541-source-library-maintenance branch from 53d58b6 to 6319f28 Compare August 14, 2026 19:57
@herzog0
herzog0 force-pushed the teo/2541-source-library-maintenance branch from 6319f28 to 6f3b5a0 Compare August 14, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Task: Wire the Library Maintenance achievement, counting libraries and not versions

2 participants