-
Notifications
You must be signed in to change notification settings - Fork 1
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
Optimize Syncing of DB entries to Translation.io #553
Comments
#745 adds an ActiveRecord query within Template.includes(phases: { sections: { questions: %i[annotations question_options] } })
.where(org_id: Org.find_by!(name: default_org_name).id)
.pluck(:title, :description,
'phases.title', 'phases.description',
'sections.title', 'sections.description',
'questions.text', 'questions.default_value',
'annotations.text',
'question_options.text')
.flatten.uniq The tables and columns here correspond with the templates-related tables that were originally in the Here is the output when executing the proc that this ActiveRecord query is contained within: 2.7.6 :001 > x = templates_data_for_default_org_proc.call
Creating scope :publicly_visible. Overwriting existing method Template.publicly_visible.
Creating scope :organisationally_visible. Overwriting existing method Template.organisationally_visible.
Org Load (0.6ms)
SELECT "orgs".*
FROM "orgs"
WHERE "orgs"."name" = $1 LIMIT $2 [["name", "Portage Network"], ["LIMIT", 1]]
(213.6ms)
SELECT "templates"."title", "templates"."description", "phases"."title", "phases"."description", "sections"."title", "sections"."description", "questions"."text", "questions"."default_value", "annotations"."text", "question_options"."text"
FROM "templates"
LEFT OUTER JOIN "phases" ON "phases"."template_id" = "templates"."id"
LEFT OUTER JOIN "sections" ON "sections"."phase_id" = "phases"."id"
LEFT OUTER JOIN "questions" ON "questions"."section_id" = "sections"."id"
LEFT OUTER JOIN "annotations" ON "annotations"."question_id" = "questions"."id"
LEFT OUTER JOIN "question_options" ON "question_options"."question_id" = "questions"."id"
WHERE "templates"."org_id" = $1 [["org_id", 8]]
=> ["CASRAI Data in Publications DMP", "<p>This is an hypothetical data management plan to support the implementation of an open access... |
2.7.6 :001 > Template.includes(phases: { sections: { questions: %i[annotations question_options] } }).pluck(:title, :description,
2.7.6 :002 > 'phases.title', 'phases.description',
2.7.6 :003 > 'sections.title', 'sections.description',
2.7.6 :004 > 'questions.text', 'questions.default_value',
2.7.6 :005 > 'annotations.text',
2.7.6 :006 > 'question_options.text').flatten.uniq.count
Creating scope :publicly_visible. Overwriting existing method Template.publicly_visible.
Creating scope :organisationally_visible. Overwriting existing method Template.organisationally_visible.
(744.2ms) SELECT "templates"."title", "templates"."description", "phases"."title", "phases"."description", "sections"."title", "sections"."description", "questions"."text", "questions"."default_value", "annotations"."text", "question_options"."text" FROM "templates" LEFT OUTER JOIN "phases" ON "phases"."template_id" = "templates"."id" LEFT OUTER JOIN "sections" ON "sections"."phase_id" = "phases"."id" LEFT OUTER JOIN "questions" ON "questions"."section_id" = "sections"."id" LEFT OUTER JOIN "annotations" ON "annotations"."question_id" = "questions"."id" LEFT OUTER JOIN "question_options" ON "question_options"."question_id" = "questions"."id"
=> 5779 2.7.6 :007 > templates_data_for_default_org_proc.call.count
Org Load (0.8ms) SELECT "orgs".* FROM "orgs" WHERE "orgs"."name" = $1 LIMIT $2 [["name", "Portage Network"], ["LIMIT", 1]]
(205.5ms) SELECT "templates"."title", "templates"."description", "phases"."title", "phases"."description", "sections"."title", "sections"."description", "questions"."text", "questions"."default_value", "annotations"."text", "question_options"."text" FROM "templates" LEFT OUTER JOIN "phases" ON "phases"."template_id" = "templates"."id" LEFT OUTER JOIN "sections" ON "sections"."phase_id" = "phases"."id" LEFT OUTER JOIN "questions" ON "questions"."section_id" = "sections"."id" LEFT OUTER JOIN "annotations" ON "annotations"."question_id" = "questions"."id" LEFT OUTER JOIN "question_options" ON "question_options"."question_id" = "questions"."id" WHERE "templates"."org_id" = $1 [["org_id", 8]]
=> 1557 On integration branch:
On PR #745 With
4222 (5779 - 1557) db entries are filtered out when we apply the There are 4205 (4476 - 271) additional purge-able translation.io keys when we apply the default org filter to the templates-related tables. The 17 entry discrepancy (4222 - 4205) may not be an issue; of the 4222 template-related entries being filtered out due to the |
The below query returns all distinct template-related-entries in the db, but first removes any of those entries which are also associated with a default_org template: def test
default_org_name = Rails.application.secrets.default_funder_name
proc do
# Return all templates data pertaining to default_org
Template.includes(phases: { sections: { questions: %i[annotations question_options] } })
.pluck(:title, :description,
'phases.title', 'phases.description',
'sections.title', 'sections.description',
'questions.text', 'questions.default_value',
'annotations.text',
'question_options.text')
.flatten.uniq - Template.includes(phases: { sections: { questions: %i[annotations question_options] } })
.where(org_id: Org.find_by!(name: default_org_name).id)
.pluck(:title, :description,
'phases.title', 'phases.description',
'sections.title', 'sections.description',
'questions.text', 'questions.default_value',
'annotations.text',
'question_options.text')
.flatten.uniq
end
end
// app/views/paginable/plans/_index.html.erb
<%= plan.visibility === 'is_test' ? _('Test') : sanitize(display_visibility(plan.visibility)) %> So 'Test' is an actual one of the 17 discrepancies that we are noticing. |
In
config/initializers/translation.rb,
we have database tables and columns specified inside of theconfig.db_fields
hash. Currently, all db entries corresponding to those (table, column) values are being sync'd to translation.io.We do not need to sync all of these entries. Rather, we only need the ones that pertain to the default funder org.
This feature should be optimized so only fields related to the default funder org are sync'd to translation.io.
The text was updated successfully, but these errors were encountered: