-
Notifications
You must be signed in to change notification settings - Fork 19
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
feat: DAH-2556 check translations cache LastModifiedDate #2283
Changes from 1 commit
56f4e55
58bb1d8
683013d
c6e4a35
7b544e3
a35e79e
7ff8e29
50b58a1
4ca33bd
d0a92c9
d4934e4
86a563e
e0eeaba
f0769d7
32434fb
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 |
---|---|---|
|
@@ -27,8 +27,12 @@ def translate(text, to) | |
end | ||
end | ||
|
||
def cache_listing_translations(listing_id, keys, translations) | ||
translations = transform_translations_for_caching(listing_id, keys, translations) | ||
def cache_listing_translations(listing_id, keys, translations, last_modified) | ||
Force::Request.new(parse_response: true).cached_get( | ||
"/ListingDetails/#{CGI.escape(listing_id)}", nil, true | ||
) | ||
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. question: It's not entirely clear to me why 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. Adding it here would guarantee that the listing is refreshed anytime we run translations for a listing. (Either by event trigger or a full process call). This solves the issue of https://sfgovdt.jira.com/browse/DAH-2575, as well as ensures the last modified date of the listing is immediately correct for when the listing service is hit. Testing through the different cases in the review instructions may provide some clarity to my above open question. 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. Based on our convo in the translations sync, can we remove the force update listing call here? |
||
translations = transform_translations_for_caching(listing_id, keys, translations, | ||
last_modified) | ||
if @cache.write("/ListingDetails/#{listing_id}/translations", translations) | ||
google_translation_logger( | ||
"Successfully cached listing translations for listing id: #{listing_id}", | ||
|
@@ -49,13 +53,13 @@ def parse_translations(results) | |
results.map(&:text) | ||
end | ||
|
||
def transform_translations_for_caching(listing_id, keys, translations) | ||
def transform_translations_for_caching(listing_id, keys, translations, last_modified) | ||
prev_cached_translations = @cache.read("/ListingDetails/#{listing_id}/translations") | ||
|
||
# keys can come from updated_values.keys in the event_subscriber_translate_service | ||
# they will be in the same order as the translations because the translation service | ||
# uses the values from that object and the api returns 1 for each key | ||
return_value = {} | ||
return_value = { LastModifiedDate: last_modified } | ||
translations.each do |target| | ||
target[:translation].each_with_index do |value, i| | ||
field = keys[i].to_sym | ||
|
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.
question: This seems to duplicate the method
CacheService#listing_unchanged?
, which gets run every 10 minutes via theprefetch
job. Does this make theprefetch
job redundant now? I.e. do we still need a background process to update caches for all modified listings every 10 minutes, when we are now doing it on every visit to a listing details page?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.
This is a good question and is related to the open question in the description.
This function compares the listing LastModifiedDate and the translations cache LastModifiedDate.
This returns false when:
A listing has been updated but the event subscriber failed to update the translations.
With the force=true call in the google_translate_service, we should always refresh the listing object when we update translations. So in theory, the LastModifiedDate of the listing should be guaranteed to be accurate for the purposes of the comparison.
If this function is false, then we process translations -> force update the listing -> translate all fields.
So yes, if the event subscriber is working -> then everytime we update a listing -> we translate and force update the listing. We could probably remove the prefetch job in this case.
If the event subscriber is down for some reason, then we would not update translations or force refresh the listing.
If we disable the prefetch job under this scenario: The listing wouldn't reflect the new changes until a manual force refresh. And we wouldn't catch the disagreement on the listing service call.
We could remove the force=true call from the google translate service, and then this check in the listing detail would return false due to the translations being newer. (Unless the prefetch job gets it first). The intended behavior would be to refresh the listing. Then the dates should match.
This ticket primarily aims to resolve the potential complications of the event subscriber failing. We do plan on implementing event replays so that is a future consideration.
Hopefully this provides some insight into the potential paths forward. We could keep the prefetch job and introduce some redundancy that would cover all of the potential scenarios.
We could remove the force=true call from the google_translation service, and just let the listing_service be responsible for updating the listing cache. Perhaps that would simplify things for us.
Maybe we should make the LastModifiedDate comparison have two outcomes: if the listing date is older than the translations -> refresh the listing. If the translation date is older than the listing -> refresh the translations.