Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record counts for review queues, including detail per promoted class #22906

Merged
merged 12 commits into from
Dec 9, 2024

Conversation

diox
Copy link
Member

@diox diox commented Dec 2, 2024

Fixes mozilla/addons#15173

Testing

manage.py cron record_reviewer_queues_counts should populate the database with QueueCount instances for the current date. There should be one instance per day per queue, plus one per promoted class. Re-running the cron for a given day should have no effect.

@diox diox changed the title Record queue counts Record counts for review queues, including detail per promoted class Dec 2, 2024
Copy link
Contributor

@KevinMind KevinMind left a comment

Choose a reason for hiding this comment

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

Few comments.

src/olympia/reviewers/utils.py Outdated Show resolved Hide resolved
src/olympia/amo/cron.py Outdated Show resolved Hide resolved
src/olympia/amo/models.py Outdated Show resolved Hide resolved
src/olympia/amo/cron.py Outdated Show resolved Hide resolved
'process_blocklistsubmissions': 'olympia.blocklist.cron',
'upload_mlbf_to_remote_settings': 'olympia.blocklist.cron',
'record_metrics': 'olympia.amo.cron',
Copy link
Member Author

@diox diox Dec 3, 2024

Choose a reason for hiding this comment

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

This is the only change in that file, rest is re-ordering alphabetically

@diox diox marked this pull request as ready for review December 3, 2024 16:23
@diox diox requested a review from KevinMind December 3, 2024 16:58
qs = Addon.unfiltered.get_queryset_for_pending_queues(
admin_reviewer=is_admin_reviewer(request.user),
show_temporarily_delayed=acl.action_allowed_for(
def get_queryset(cls, request, *, upcoming_due_date_focus=False, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is there a reason not to simply define the 3 relevant properties as args and let the view pass in the arguments from else and the cron pass in the hard coded values. IMO that makes it super clear at the call site what is going on, whereas now both are kind of obfuscated.. If there is a good reason to keep the request in context then fine, but otherwise that seems like the better way to go, don't you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

I had a version with this idea that I didn't push: I had renamed get_queryset() as get_base_queryset(), the views would call get_queryset(request) which would then call get_base_queryset() with the right arguments, the cron would directly call get_base_queryset() (with no arguments, the default values were what we needed).

But ultimately I scrapped it because it was very verbose (each table needed to have those 2 methods, even when they didn't implement anything special) and I found the extra layer more confusing when re-reading the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why it needs to be 2 methods. it could just be one method with the defined arguments.

get_queryset(
    admin_reviewer=False,
    show_temporarily_delayed = True,
    show_only_upcoming = False,
)

Then in the view we can pull the arguments from the request.

admin_reviewer = is_admin_reviewer(request.user)
show_temporarily_delayed = acl.action_allowed_for(
    request.user, amo.permissions.ADDONS_TRIAGE_DELAYED
)
show_only_upcoming = upcoming_due_date_focus and not acl.action_allowed_for(
    request.user, amo.permissions.ADDONS_ALL_DUE_DATES
)

table = TheClass.get_queryset(
    admin_reviewer=admin_reviewer,
    show_temporarily_delayed=show_temporarily_delayed,
    show_only_upcoming=show_only_upcoming,
)

... do stuff with table

And in the cron we just directly set whatever arguments we want... would something like this not work and achieve my goal of keeping the control logic at the call site? You can say yes and also not implement it, but wondering if this would work in your view?

Copy link
Member Author

Choose a reason for hiding this comment

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

Something like that would work, yes, but I was trying to avoid more duplication of code. The code to check for show_temporarily_delayed / admin_reviewer is needed in the queue view... but also the dashboard, which fetches the counts (personalized for the current user according to what they'd be able to see). The single get_queryset() method avoids that duplication currently.

Copy link
Contributor

@KevinMind KevinMind left a comment

Choose a reason for hiding this comment

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

Okay. I won't die on this hill but I think that kind of code duplication is totally okay and arguably better than including additional (unnecessary) context into the "service" layer. Keeping that layer args only not only simplifies testing (just pass all combination of arguments and verify the results, no need to mock requests) it also exposes the actual expectations each caller has for the service, since the code is defined and readable at the point of dependency. This is totally worth sacrificing one unit of DRY imo.

I will verify and approve. Speaking of... how should I verify the counts themselves are correct. Are we expecting the length of the queue in reviewer tools should match that of the QueueCount instance? How would one verify this using the admin?

@diox
Copy link
Member Author

diox commented Dec 9, 2024

I will verify and approve. Speaking of... how should I verify the counts themselves are correct. Are we expecting the length of the queue in reviewer tools should match that of the QueueCount instance? How would one verify this using the admin?

At the most basic level, you need a bunch of add-ons in the queues, which can be achieved by:

  • Submitting themes / theme versions, for the theme queue
  • Submitting extensions / extensions versions and forcing their versions not to be auto-approved and marked as needing human review, for the manual review queue (quickest way is probably to add NeedsHumanReview instance for each version - reason doesn't matter, as long as is_active stays True - and don't auto-approve them)

Then if you are a superuser (so you have all permissions) the count in the dashboard for each queue should match the value in the corresponding QueueCount for that day, as well as the number of visible items in the queue page itself (including pagination if needed)

(You can't verify this in the admin, have to open a django shell)

There are a lot more combinations since depending on permissions you should not see the same contents in some queues (but the QueueCount should stay the same) and more queues than that, but I think this would be a lot easier to fully verify on dev (which has all the relevant data) if the logic looks ok. Existing unit tests should also ensure I've not regressed the queues in my refactor.

Copy link
Contributor

@KevinMind KevinMind left a comment

Choose a reason for hiding this comment

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

Agree, this requires a lot of preparation data already covered in the tests so let's verify on dev.

@diox diox merged commit 1be011d into mozilla:master Dec 9, 2024
31 checks passed
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]: Record the number of add-ons pending a manual review on a daily basis
2 participants