benwbrum / fromthepage

FromThePage is a wiki-like application for crowdsourcing transcription of handwritten documents.
http://fromthepage.com
GNU Affero General Public License v3.0
170 stars 50 forks source link

New FindAProject page performance problems #4129

Open benwbrum opened 4 months ago

benwbrum commented 4 months ago

The new landing page is taking an average of 6-7 seconds to load.

This query is taking 3340ms to run:

app/views/dashboard/new_landing_page.html.slim:41:in `_app_views_dashboard_new_landing_page_html_slim___2538418121397893880_7470340'
app/controllers/application_controller.rb:64:in `switch_locale'
SELECT `users`.`id` AS t0_r0, `users`.`login` AS t0_r1, `users`.`display_name` AS t0_r2, `users`.`real_name` AS t0_r3, `users`.`email` AS t0_r4, `users`.`owner` AS t0_r5, `users`.`admin` AS t0_r6, `users`.`encrypted_password` AS t0_r7, `users`.`password_salt` AS t0_r8, `users`.`created_at` AS t0_r9, `users`.`updated_at` AS t0_r10, `users`.`remember_token` AS t0_r11, `users`.`remember_token_expires_at` AS t0_r12, `users`.`location` AS t0_r13, `users`.`website` AS t0_r14, `users`.`about` AS t0_r15, `users`.`reset_password_token` AS t0_r16, `users`.`reset_password_sent_at` AS t0_r17, `users`.`remember_created_at` AS t0_r18, `users`.`sign_in_count` AS t0_r19, `users`.`current_sign_in_at` AS t0_r20, `users`.`last_sign_in_at` AS t0_r21, `users`.`current_sign_in_ip` AS t0_r22, `users`.`last_sign_in_ip` AS t0_r23, `users`.`account_type` AS t0_r24, `users`.`paid_date` AS t0_r25, `users`.`guest` AS t0_r26, `users`.`slug` AS t0_r27, `users`.`deleted` AS t0_r28, `users`.`provider` AS t0_r29, `users`.`uid` AS t0_r30, `users`.`start_date` AS t0_r31, `users`.`orcid` AS t0_r32, `users`.`dictation_language` AS t0_r33, `users`.`activity_email` AS t0_r34, `users`.`external_id` AS t0_r35, `users`.`sso_issuer` AS t0_r36, `users`.`preferred_locale` AS t0_r37, `users`.`api_key` AS t0_r38, `users`.`picture` AS t0_r39, `users`.`help` AS t0_r40, `users`.`footer_block` AS t0_r41, `collections`.`id` AS t1_r0, `collections`.`title` AS t1_r1, `collections`.`owner_user_id` AS t1_r2, `collections`.`created_on` AS t1_r3, `collections`.`intro_block` AS t1_r4, `collections`.`footer_block` AS t1_r5, `collections`.`restricted` AS t1_r6, `collections`.`picture` AS t1_r7, `collections`.`supports_document_sets` AS t1_r8, `collections`.`subjects_disabled` AS t1_r9, `collections`.`transcription_conventions` AS t1_r10, `collections`.`slug` AS t1_r11, `collections`.`hide_completed` AS t1_r12, `collections`.`help` AS t1_r13, `collections`.`link_help` AS t1_r14, `collections`.`field_based` AS t1_r15, `collections`.`voice_recognition` AS t1_r16, `collections`.`language` AS t1_r17, `collections`.`text_language` AS t1_r18, `collections`.`license_key` AS t1_r19, `collections`.`pct_completed` AS t1_r20, `collections`.`default_orientation` AS t1_r21, `collections`.`is_active` AS t1_r22, `collections`.`works_count` AS t1_r23, `collections`.`next_untranscribed_page_id` AS t1_r24, `collections`.`api_access` AS t1_r25, `collections`.`facets_enabled` AS t1_r26, `collections`.`user_download` AS t1_r27, `collections`.`review_type` AS t1_r28, `collections`.`data_entry_type` AS t1_r29, `collections`.`description_instructions` AS t1_r30, `collections`.`enable_spellcheck` AS t1_r31, `collections`.`messageboard_slug` AS t1_r32, `collections`.`thredded_messageboard_group_id` AS t1_r33, `collections`.`messageboards_enabled` AS t1_r34, `collections`.`most_recent_deed_created_at` AS t1_r35, `collections`.`alphabetize_works` AS t1_r36 FROM `users` INNER JOIN `collections` ON `collections`.`owner_user_id` = `users`.`id` LEFT OUTER JOIN `document_sets` ON `document_sets`.`owner_user_id` = `users`.`id` WHERE `users`.`owner` = TRUE AND NOT ((`users`.`account_type` IN ('Trial', 'Staff') OR `users`.`account_type` IS NULL)) ORDER BY `users`.`display_name` ASC; 
benwbrum commented 4 months ago

Line 41 of the view is

    -@owners.each do |owner|

Since that's the first time we access @owners, AREL is probably waiting until then to execute the query.

Here is the query in dashboard_controller.rb:


    # Get random Collections and DocSets from paying users
    @owners = User.findaproject_owners.order(:display_name).joins(:collections)
                  .left_outer_joins(:document_sets).includes(:collections)
benwbrum commented 4 months ago

The old findaproject page has similar performance problems.