-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve performance of
CinderJob.resolvable_in_reviewer_tools()
/ `…
…CinderJob.for_addon()` (#21882) * Improve performance of CinderJob.resolvable_in_reviewer_tools() / CinderJob.for_addon() Add denormalized fields to help figure out whether a CinderJob is for a particular add-on and whether it's meant for AMO reviewers, which greatly simplifies the corresponding queries, improving their performance. - `target_addon` is set at reporting time and never changes after - `resolvable_in_reviewer_tools` is also set at reporting time but can be flipped when processing escalations from Cinder.
- Loading branch information
Showing
10 changed files
with
357 additions
and
51 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/olympia/abuse/management/commands/fill_cinderjobs_denormalized_fields.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from django.core.management.base import BaseCommand | ||
|
||
from olympia.abuse.models import CinderJob | ||
|
||
|
||
class Command(BaseCommand): | ||
help = ( | ||
'One-off command to fill CinderJob.target_addon and ' | ||
'CinderJob.resolvable_in_reviewer_tools fields' | ||
) | ||
|
||
def handle(self, *args, **options): | ||
jobs = CinderJob.objects.all() | ||
|
||
for job in jobs: | ||
if abuse_report := job.initial_abuse_report: | ||
job.target_addon = ( | ||
# If the abuse report is against a guid, set target_addon | ||
# on the job accordingly. | ||
abuse_report.guid and abuse_report.target | ||
) | ||
job.resolvable_in_reviewer_tools = ( | ||
# If the abuse report was meant to be handled by reviewers | ||
# from the start or it's been escalated, set | ||
# resolvable_in_reviewer_tools accordingly. | ||
abuse_report.is_handled_by_reviewers | ||
or job.decision_action | ||
== CinderJob.DECISION_ACTIONS.AMO_ESCALATE_ADDON | ||
) | ||
job.save() |
29 changes: 29 additions & 0 deletions
29
src/olympia/abuse/migrations/0025_cinderjob_resolvable_in_reviewer_tools_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generated by Django 4.2.9 on 2024-02-19 10:53 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("addons", "0049_clear_bad_url_data"), | ||
("abuse", "0024_cinderpolicy_parent_alter_cinderpolicy_uuid"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="cinderjob", | ||
name="resolvable_in_reviewer_tools", | ||
field=models.BooleanField(default=None, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="cinderjob", | ||
name="target_addon", | ||
field=models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.SET_NULL, | ||
to="addons.addon", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
from django.core.management import call_command | ||
|
||
from olympia.abuse.models import AbuseReport, CinderJob | ||
from olympia.amo.tests import TestCase, addon_factory, user_factory | ||
|
||
|
||
class TestFillCinderJob(TestCase): | ||
def test_fill_somehow_no_abuse_reports(self): | ||
job = CinderJob.objects.create(job_id='job123') | ||
|
||
call_command('fill_cinderjobs_denormalized_fields') | ||
|
||
job.reload() | ||
assert not job.target_addon | ||
assert not job.resolvable_in_reviewer_tools | ||
|
||
def test_fill_addon(self): | ||
addon_factory() # Extra add-on, shouldn't matter. | ||
addon = addon_factory() | ||
job = CinderJob.objects.create(job_id='job123') | ||
report = AbuseReport.objects.create(guid=addon.guid, cinder_job=job) | ||
|
||
call_command('fill_cinderjobs_denormalized_fields') | ||
|
||
job.reload() | ||
assert job.target_addon == report.target == addon | ||
assert not job.resolvable_in_reviewer_tools | ||
|
||
def test_fill_appealed_job(self): | ||
addon_factory() # Extra add-on, shouldn't matter. | ||
addon = addon_factory() | ||
job = CinderJob.objects.create( | ||
job_id='job123', appeal_job=CinderJob.objects.create(job_id='appeal123') | ||
) | ||
report = AbuseReport.objects.create(guid=addon.guid, cinder_job=job) | ||
|
||
call_command('fill_cinderjobs_denormalized_fields') | ||
|
||
job.reload() | ||
assert job.target_addon == report.target == addon | ||
assert not job.resolvable_in_reviewer_tools | ||
job.appeal_job.reload() | ||
assert job.appeal_job.target_addon == report.target == addon | ||
assert not job.appeal_job.resolvable_in_reviewer_tools | ||
|
||
def test_fill_non_addon(self): | ||
user = user_factory() | ||
job = CinderJob.objects.create(job_id='job123') | ||
AbuseReport.objects.create(user=user, cinder_job=job) | ||
|
||
call_command('fill_cinderjobs_denormalized_fields') | ||
|
||
job.reload() | ||
assert job.target_addon is None | ||
assert not job.resolvable_in_reviewer_tools | ||
|
||
def test_fill_resolvable_in_reviewer_tools(self): | ||
addon_factory() # Extra add-on, shouldn't matter. | ||
addon = addon_factory() | ||
job = CinderJob.objects.create(job_id='job123') | ||
report = AbuseReport.objects.create( | ||
guid=addon.guid, | ||
cinder_job=job, | ||
location=AbuseReport.LOCATION.BOTH, | ||
reason=AbuseReport.REASONS.POLICY_VIOLATION, | ||
) | ||
|
||
call_command('fill_cinderjobs_denormalized_fields') | ||
|
||
job.reload() | ||
assert job.target_addon == report.target == addon | ||
assert job.resolvable_in_reviewer_tools | ||
|
||
def test_fill_not_resolvable_in_reviewer_tools(self): | ||
addon_factory() # Extra add-on, shouldn't matter. | ||
addon = addon_factory() | ||
job = CinderJob.objects.create(job_id='job123') | ||
# Location makes it not resolvable in reviewer tools unless escalated | ||
# even though the reason is policy violation. | ||
report = AbuseReport.objects.create( | ||
guid=addon.guid, | ||
cinder_job=job, | ||
location=AbuseReport.LOCATION.AMO, | ||
reason=AbuseReport.REASONS.POLICY_VIOLATION, | ||
) | ||
|
||
call_command('fill_cinderjobs_denormalized_fields') | ||
|
||
job.reload() | ||
assert job.target_addon == report.target == addon | ||
assert not job.resolvable_in_reviewer_tools | ||
|
||
def test_fill_escalated_addon(self): | ||
addon_factory() # Extra add-on, shouldn't matter. | ||
addon = addon_factory() | ||
job = CinderJob.objects.create( | ||
job_id='job123', | ||
decision_action=CinderJob.DECISION_ACTIONS.AMO_ESCALATE_ADDON, | ||
) | ||
report = AbuseReport.objects.create(guid=addon.guid, cinder_job=job) | ||
|
||
call_command('fill_cinderjobs_denormalized_fields') | ||
|
||
job.reload() | ||
assert job.target_addon == report.target == addon | ||
assert job.resolvable_in_reviewer_tools |
Oops, something went wrong.