diff --git a/CHANGELOG.md b/CHANGELOG.md index 3aeeb4e2f3..6f39b9613b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,16 @@ # Changelog +Performance improvements +- Update ActiveRecord query on the answers_controller so that it stops performing a `select * from answers where question id in (???)` and instead uses `select * from answers where question id in (???) AND plan_id = ?`. +- Add an index to the `settings` table. This table is written to every time someone downloads their plan, and is read each time the download page is loaded. +- Update ActiveRecord query on the plans_controller's download action so that it `includes` settings + + ## v4.2.0 -**Note this upgrade is mainly a migration from Bootstrap 3 to Bootstrap 5.** +**Note this upgrade is mainly a migration from Bootstrap 3 to Bootstrap 5.** -Note that this will have a significant impact on any scss and html customizations you may have made to your fork of this project. +Note that this will have a significant impact on any scss and html customizations you may have made to your fork of this project. The following links will be helpful: @@ -17,9 +23,9 @@ The following links will be helpful: [What happened to $grid-float-breakpoint in Bootstrap 4. And screen size breakpoint shift from 3 -> 4]( https://bibwild.wordpress.com/2019/06/10/what-happened-to-grid-float-breakpoint-in-bootstrap-4-and-screen-size-breakpoint-shift-from-3-4/)
[What are media queries in Bootstrap 4?](https://www.educative.io/answers/what-are-media-queries-in-bootstrap-4)
- + ### Key changes - + - Node package changes: * Changed version of `bootstrap "^3.4.1"` --> `"^5.2.3"` * Added `@popperjs/core.` @@ -37,7 +43,7 @@ https://bibwild.wordpress.com/2019/06/10/what-happened-to-grid-float-breakpoint- + `@use "../../../../node_modules/bootstrap-sass/assets/stylesheets/_bootstrap.scss" as * ;`
with
`@use "../../../../node_modules/bootstrap/scss/bootstrap" as *;` - + Enclosed all division calculations using symbol `/` with `calc()` function,
+ + Enclosed all division calculations using symbol `/` with `calc()` function,
e.g., replaced
`padding-right: $grid-gutter-width / 2;`
with
@@ -46,7 +52,7 @@ https://bibwild.wordpress.com/2019/06/10/what-happened-to-grid-float-breakpoint- - `@media (max-width: $grid-float-breakpoint-max) {}`
with
`@include media-breakpoint-down(md){}` - + - `@media (max-width: $grid-float-breakpoint-max) {}`
with
`@include media-breakpoint-down(md) {}` @@ -67,7 +73,7 @@ When we use a native DOM element in Javascript, we obtain it by applying get() t We sometimes use the button native Dom element to programmatically click, as the Jquery button element with trigger('click') won't work because the trigger() function cannot be used to mimic native browser events, such as clicking (cf., https://learn.jquery.com/events/triggering-event-handlers/ ) + Accordion & spinners - - Bespoke versions replaced by Bootstrap 5 accordion and spinner now. + - Bespoke versions replaced by Bootstrap 5 accordion and spinner now. - Accordion * Changed the default Bootstrap arrow icon for the accordion to use the fontawesome icons plus and minus icons. Created a several accordion specific colour variables:
// Accordion colors @@ -83,7 +89,7 @@ We sometimes use the button native Dom element to programmatically click, as the - Bootstrap dropped `btn-block` class for utilities. So we removed any styling using it. - Close Buttons: Renamed `close` to`btn-close`. - Renamed `btn-default` to `btn-secondary` and variable `$btn-default-color` changed to `$btn-secondary-color`. -+ Dropdowns ++ Dropdowns - Dropdown list items with class `dropdown` have class `dropdown-item` added usually with`px-3` for positioning. - Added new `dropdown-menu-dark` variant and associated variables for on-demand dark dropdowns. - Data attributes changes required by Bootstrap 5 (as used by accordion and dropdown buttons): @@ -92,7 +98,7 @@ We sometimes use the button native Dom element to programmatically click, as the * `data-target` --> `data-bs-target` * `data-toggle` --> `data-bs-toggle` - Bootstrap 5 Popover added to some dropdown-menu items by adding attribute `data-bs-toggle="popover"` -+ Form ++ Form - `form-group` class replaced with `form-control`. - Form labels now require `form-label` or `form-check-label` to go with `form-control` and `form-check` respectively. So all obsolete `control-label` replaced by `form-label` and missing ones added. - Dropped form-specific layout classes for our grid system. Use Bootstrap grid and utilities instead of `form-group`, `form-row`, or `form-inline`. @@ -119,7 +125,7 @@ We sometimes use the button native Dom element to programmatically click, as the - Bootstrap rewrote component with flexbox. Dropped nearly all > selectors for simpler styling via un-nested classes. Instead of HTML-specific selectors like .nav > li > a, we use separate classes for `navs, nav-items, and nav-links`. (Note because the `nav-link` class has not always been added as it comes with styles not appropriate for our styling for links.) This makes your HTML more flexible while bringing along increased extensibility. So we have dropped HTML-specific selectors and css in `_navs.scss` - e.g., + e.g.,
`.nav-tabs > li > a:hover` --> `nav-tabs nav-link:hover`,
`.nav-pills > li > a:hover` -->`nav-pills .nav-link:hover`. - Pages with css classes `nav` and`navbar` updated to work with Bootstrap 5. So `app/assets/stylesheets/blocks/_navbars.scss` and `app/assets/stylesheets/blocks/_navs.scss` updated. @@ -131,8 +137,8 @@ We sometimes use the button native Dom element to programmatically click, as the + Notifications - Notifications now use classes `d-block` and `d-none` to show and hide respectively. + Panels, thumbnails & wells (replacements) - - Bootstrap 5 dropped panels, thumbnails and wells. So pages with them updated with Bootstrap 5 replacements. - * All views with css classes`panel, panel-body, panel-*` Have panel replaced by card to give `card, card_body, card-*`, etc. + - Bootstrap 5 dropped panels, thumbnails and wells. So pages with them updated with Bootstrap 5 replacements. + * All views with css classes`panel, panel-body, panel-*` Have panel replaced by card to give `card, card_body, card-*`, etc. * As `panel-default` and some otherpanel css classes don't have card equivalents with same suffixes we have added these classes temporarily in `_cards.sccs`, e.g.,`.card-default`, etc. + Utilities - Bootstrap renamed several utilities to use logical property names instead of directional names with the addition of RTL support: @@ -147,9 +153,9 @@ We sometimes use the button native Dom element to programmatically click, as the * As Bootstrap 5.2 dropped class `text-justify` we have created a custom version based on comment https://github.com/twbs/bootstrap/pull/29793#issuecomment-1814683346 * `text-*` utilities do not add hover and focus states to links anymore. `link-*` helper classes can be used instead. -### Fixed -- Fixed rubocop errors after Bootstrap upgrade -- Fixed RSpec tests after Bootstrap upgrade +### Fixed +- Fixed rubocop errors after Bootstrap upgrade +- Fixed RSpec tests after Bootstrap upgrade - Fix "undefined" Tooltip Messages [#3364](https://github.com/DMPRoadmap/roadmap/pull/3364) - Fixed rubocop errors after V4.1.1 release - Fixed MySQL and PostgreSQL GitHub Actions [PR #3376](https://github.com/DMPRoadmap/roadmap/pull/3376) diff --git a/app/controllers/answers_controller.rb b/app/controllers/answers_controller.rb index 43ab3127fc..4648245805 100644 --- a/app/controllers/answers_controller.rb +++ b/app/controllers/answers_controller.rb @@ -86,14 +86,8 @@ def create_or_update # check should probably happen on create/update # rubocop:disable Style/GuardClause if @answer.present? - @plan = Plan.includes( - sections: { - questions: %i[ - answers - question_format - ] - } - ).find(p_params[:plan_id]) + @plan = Plan.includes(answers: { question: [:question_format] }) + .find(p_params[:plan_id]) @question = @answer.question @section = @plan.sections.find_by(id: @question.section_id) template = @section.phase.template diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 8f7c44393a..6dbc2ce75d 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -373,7 +373,9 @@ def answer # GET /plans/:id/download def download - @plan = Plan.find(params[:id]) + @plan = Plan.includes(:research_outputs, template: [:phases], roles: [:user]) + .find(params[:id]) + @has_research_outputs = @plan.research_outputs.any? authorize @plan @phase_options = @plan.phases.order(:number).pluck(:title, :id) @phase_options.insert(0, ['All phases', 'All']) if @phase_options.length > 1 diff --git a/app/views/plans/_download_form.html.erb b/app/views/plans/_download_form.html.erb index 5100a71b5a..09a9fda3ca 100644 --- a/app/views/plans/_download_form.html.erb +++ b/app/views/plans/_download_form.html.erb @@ -42,7 +42,7 @@ <%= _('unanswered questions') %> <% end %> - <% if @plan.research_outputs.any? %> + <% if @has_research_outputs %>
<%= label_tag 'export[research_outputs]', class:'form-check-label' do %> <%= check_box_tag 'export[research_outputs]', true, true %> diff --git a/db/migrate/20240617115900_add_index_to_settings.rb b/db/migrate/20240617115900_add_index_to_settings.rb new file mode 100644 index 0000000000..488009ba20 --- /dev/null +++ b/db/migrate/20240617115900_add_index_to_settings.rb @@ -0,0 +1,5 @@ +class AddIndexToSettings < ActiveRecord::Migration[6.1] + def change + add_index :settings, [:target_id, :target_type], name: 'settings_target' + end +end \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index ae11e2f118..6afb9da097 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -505,6 +505,7 @@ t.string "target_type" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["target_id", "target_type"], name: "settings_target" end create_table "stats", id: :integer, force: :cascade do |t|