-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Process Repeaters, Part 1 #35033
base: master
Are you sure you want to change the base?
Process Repeaters, Part 1 #35033
Changes from 1 commit
50c848a
0db6a6c
e36296c
aeb10ba
01e4bc7
db2fec2
85b952e
c28c11b
d8d9642
48c3d7c
418ed3a
85bbfa3
d1119bb
03b26cf
de27ba0
4955ef4
59aae71
f40e6f4
b70fc52
7e65b3b
4c41896
30d4a6f
fc0f174
e32b465
e3bcd74
efc4dde
bd37a00
a448b9e
4321fb7
74137f9
968a922
4fd14a0
07320b9
b1eb171
2463348
8a7f343
0f72ba9
7f18e52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,49 +12,61 @@ class Migration(migrations.Migration): | |||||
migrations.SeparateDatabaseAndState( | ||||||
state_operations=[ | ||||||
migrations.AlterField( | ||||||
model_name="repeatrecord", | ||||||
name="state", | ||||||
field=models.PositiveSmallIntegerField( | ||||||
choices=[ | ||||||
(1, "Pending"), | ||||||
(2, "Failed"), | ||||||
(4, "Succeeded"), | ||||||
(8, "Cancelled"), | ||||||
(16, "Empty"), | ||||||
(32, "Invalid Payload"), | ||||||
], | ||||||
db_index=True, | ||||||
default=1, | ||||||
), | ||||||
model_name="repeater", | ||||||
name="is_deleted", | ||||||
field=models.BooleanField(default=False), | ||||||
), | ||||||
migrations.AddIndex( | ||||||
model_name="repeater", | ||||||
index=models.Index( | ||||||
condition=models.Q(("is_deleted", False), ("is_paused", False)), | ||||||
fields=["next_attempt_at"], | ||||||
name="next_attempt_at_partial_idx", | ||||||
condition=models.Q(("is_deleted", False)), | ||||||
fields=["id"], | ||||||
name="is_deleted_partial_idx", | ||||||
), | ||||||
), | ||||||
migrations.AddIndex( | ||||||
model_name="repeatrecord", | ||||||
index=models.Index( | ||||||
condition=models.Q(("state__in", (1, 2))), | ||||||
fields=["repeater_id"], | ||||||
name="state_partial_idx", | ||||||
), | ||||||
), | ||||||
], | ||||||
|
||||||
database_operations=[ | ||||||
# Drop `Repeater.id_deleted` index | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
migrations.RunSQL( | ||||||
sql=""" | ||||||
CREATE INDEX CONCURRENTLY "repeaters_repeatrecord_state_8055083b" | ||||||
ON "repeaters_repeatrecord" ("state"); | ||||||
DROP INDEX CONCURRENTLY "repeaters_repeater_is_deleted_08441bf0"; | ||||||
""", | ||||||
reverse_sql=""" | ||||||
DROP INDEX CONCURRENTLY "repeaters_repeatrecord_state_8055083b"; | ||||||
CREATE INDEX CONCURRENTLY "repeaters_repeater_is_deleted_08441bf0" | ||||||
ON "repeaters_repeater" ("is_deleted"); | ||||||
""" | ||||||
), | ||||||
|
||||||
# Replace with a partial index on `id_` column | ||||||
migrations.RunSQL( | ||||||
sql=""" | ||||||
CREATE INDEX CONCURRENTLY "is_deleted_partial_idx" | ||||||
ON "repeaters_repeater" ("id_") | ||||||
WHERE NOT "is_deleted"; | ||||||
""", | ||||||
reverse_sql=""" | ||||||
DROP INDEX CONCURRENTLY "is_deleted_partial_idx"; | ||||||
""" | ||||||
), | ||||||
|
||||||
# Add partial index for RepeatRecord.state on `repeater_id` | ||||||
migrations.RunSQL( | ||||||
sql=""" | ||||||
CREATE INDEX CONCURRENTLY "next_attempt_at_partial_idx" | ||||||
ON "repeaters_repeater" ("next_attempt_at") | ||||||
WHERE (NOT "is_deleted" AND NOT "is_paused"); | ||||||
CREATE INDEX CONCURRENTLY "state_partial_idx" | ||||||
ON "repeaters_repeatrecord" ("repeater_id_") | ||||||
WHERE "state" IN (1, 2); | ||||||
""", | ||||||
reverse_sql=""" | ||||||
DROP INDEX CONCURRENTLY "next_attempt_at_partial_idx"; | ||||||
DROP INDEX CONCURRENTLY "state_partial_idx"; | ||||||
""" | ||||||
), | ||||||
] | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,7 +288,7 @@ class Repeater(RepeaterSuperProxy): | |
max_workers = models.IntegerField(default=0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of spinning this feature off in a separate PR (if we decided it's needed)? We have a lot of knobs to turn already, and I wonder if we'll need this one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We needed this one years ago. OpenMRS integrations involve Events and Observations, and it is really useful if we can send repeat records in the order in which their forms were submitted. More generally, setting And setting it to [all of the workers] is an insurance policy for this PR to ensure that we can still handle the highest volume for repeaters that need it. I'd sleep easier if this is included. |
||
options = JSONField(default=dict) | ||
connection_settings_id = models.IntegerField(db_index=True) | ||
is_deleted = models.BooleanField(default=False, db_index=True) | ||
is_deleted = models.BooleanField(default=False) | ||
last_modified = models.DateTimeField(auto_now=True) | ||
date_created = models.DateTimeField(auto_now_add=True) | ||
|
||
|
@@ -299,9 +299,9 @@ class Meta: | |
db_table = 'repeaters_repeater' | ||
indexes = [ | ||
models.Index( | ||
fields=['next_attempt_at'], | ||
condition=models.Q(("is_deleted", False), ("is_paused", False)), | ||
name='next_attempt_at_partial_idx', | ||
name='is_deleted_partial_idx', | ||
fields=['id'], | ||
condition=models.Q(is_deleted=False), | ||
), | ||
] | ||
|
||
|
@@ -1037,7 +1037,6 @@ class RepeatRecord(models.Model): | |
state = models.PositiveSmallIntegerField( | ||
choices=State.choices, | ||
default=State.Pending, | ||
db_index=True, | ||
) | ||
registered_at = models.DateTimeField() | ||
next_check = models.DateTimeField(null=True, default=None) | ||
|
@@ -1053,7 +1052,12 @@ class Meta: | |
name="next_check_not_null", | ||
fields=["next_check"], | ||
condition=models.Q(next_check__isnull=False), | ||
) | ||
), | ||
models.Index( | ||
name="state_partial_idx", | ||
fields=["repeater_id"], | ||
condition=models.Q(state__in=(State.Pending, State.Fail)), | ||
), | ||
] | ||
constraints = [ | ||
models.CheckConstraint( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder what are the computational differences in Postgres for
state IN (1, 2)
vsstate = 1 OR state = 2
? I hope they are virtually the same, but it would be a shame ifIN (...)
does something complicated with a loop.