-
Notifications
You must be signed in to change notification settings - Fork 36
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
Improve Sync To User performance (batch 2) #1897
Changes from all commits
1ef492c
18247a5
e6c99e6
25b5a20
5f0a890
2a40c22
5129124
a25afe4
a789fd6
b856e3f
d8a8311
bd8306c
a664679
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,7 +12,7 @@ def sync_to_user | |
|
||
private | ||
|
||
def region_records | ||
def model_sync_scope | ||
super.for_v3 | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,6 +215,10 @@ def valid_block | |
end | ||
end | ||
|
||
def prioritized_patients | ||
registered_patients.with_discarded | ||
end | ||
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. Is this a bit dissonant? "Syncable" in general means you are registered in, assigned to, or plan to visit. We're using a simplified definition here because it doesn't really matter when used for facility prioritization. However, does this set us up to do things like facility-level sync incorrectly? 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. To address the dissonance, I suspect we'd either:
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.
|
||
|
||
def self.localized_facility_size(facility_size) | ||
return unless facility_size | ||
I18n.t("activerecord.facility.facility_size.#{facility_size}", default: facility_size.capitalize) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,7 @@ class PrescriptionDrug < ApplicationRecord | |
validates :is_protocol_drug, inclusion: {in: [true, false]} | ||
validates :is_deleted, inclusion: {in: [true, false]} | ||
|
||
scope :syncable_to_region, ->(region) { | ||
with_discarded.where(patient: Patient.syncable_to_region(region)) | ||
} | ||
scope :for_sync, -> { with_discarded } | ||
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. Can we add a couple tiny tests for this scope across these models? |
||
|
||
def self.prescribed_as_of(date) | ||
where("device_created_at <= ?", date.end_of_day) | ||
|
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 think I understand why you are returning a AR scope here instead of the actual model, but its a confusing mismatch with the name and conventions around something named
model
. Maybe rename the method to something likescope
to better represent that its the base scope for other methods to build off of? Or mayberegion_scope
,sync_scope
,default_sync_scope
?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.
Yeah, I wasn't happy with continuing to calling it
model
. We'd removedmodel
earlier because I disliked its hanging presence with invisible meanings. But I thinksync_scope
makes sense 👍🏼