discourse/spec/models
Sam 29fac1ac18 PERF: improve performance of unread queries
Figuring out what unread topics a user has is a very expensive
operation over time.

Users can easily accumulate 10s of thousands of tracking state rows
(1 for every topic they ever visit)

When figuring out what a user has that is unread we need to join
the tracking state records to the topic table. This can very quickly
lead to cases where you need to scan through the entire topic table.

This commit optimises it so we always keep track of the "first" date
a user has unread topics. Then we can easily filter out all earlier
topics from the join.

We use pg functions, instead of nested queries here to assist the
planner.
2017-05-25 15:07:30 -04:00
..
about_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
admin_dashboard_data_spec.rb Add failing tests 2017-02-15 00:05:58 -08:00
api_key_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
application_request_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
backup_spec.rb FEATURE: Support subfolders in `SiteSetting.s3_backup_bucket`. 2016-08-15 16:14:51 +08:00
badge_spec.rb Reset `I18n.locale` in tests. 2016-09-29 13:42:56 +08:00
badge_type.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
category_featured_topic_spec.rb FEATURE: each category can control how many topics to show on categories page 2017-03-01 15:12:57 -05:00
category_featured_user_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
category_group_spec.rb Enums that are used in tables need to be stable 2016-01-08 20:43:11 +05:30
category_list_spec.rb FEATURE: each category can control how many topics to show on categories page 2017-03-01 15:12:57 -05:00
category_spec.rb FEATURE: staff can set a timer to remind them about a topic 2017-05-16 14:49:50 -04:00
category_user_spec.rb remove rails-observers 2016-12-22 16:46:53 +11:00
color_scheme_color_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
color_scheme_spec.rb FIX: correctly invalidate theme css cache on scheme change 2017-05-10 15:47:11 -04:00
developer_spec.rb FEATURE: allow "developer" account flagging via developers table 2016-07-28 10:14:06 +10:00
digest_email_site_setting_spec.rb FEATURE: More digest email frequency options. Digests can be sent as often as every 30 minutes. 2016-03-02 15:43:47 -05:00
directory_item_spec.rb remove rails-observers 2016-12-22 16:46:53 +11:00
discourse_single_sign_on_spec.rb FIX: require re-activation if SSO changes email and updates it 2017-05-16 16:18:18 -04:00
draft_sequence_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
draft_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
email_change_request_spec.rb FIX: Don't allow invalid email to be saved. 2016-12-21 17:47:11 +08:00
email_log_spec.rb improve specs 2017-05-03 17:48:33 +05:30
email_token_spec.rb FEATURE: remove email_token_grace_period_hours 2016-12-19 17:15:20 +11:00
embeddable_host_spec.rb Allow ports for embed host IPs 2017-03-15 18:16:34 -03:00
emoji_spec.rb FIX: `CustomEmoji` may contain an invalid upload_id. 2017-05-05 14:53:38 +08:00
given_daily_like_spec.rb FIX: Use a logging table for daily likes given. Use it for badges. 2016-03-18 11:18:54 -04:00
global_setting_spec.rb correct logic, so revalidation is reset 2017-03-13 10:47:43 -04:00
group_history_spec.rb FEATURE: Group logs. 2016-12-12 17:29:54 +08:00
group_spec.rb FIX: `Group#name` is case insensitive. 2017-03-06 17:24:03 +08:00
group_user_spec.rb FEATURE: default notification level for group messages 2017-04-20 15:47:35 -04:00
incoming_link_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
incoming_links_report_spec.rb FIX: broken links on admin dashboard in Top Referrers section 2016-02-22 14:31:13 -05:00
invite_redeemer_spec.rb FIX: always send password reset email when accepting invite if password is not set 2017-04-18 14:37:06 +05:30
invite_spec.rb FIX: rescue specific errors on invite failure 2017-05-02 15:13:33 +05:30
locale_site_setting_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
mailing_list_mode_site_setting_spec.rb Remove daily mailing mode option as it doesn't scale. 2017-05-05 12:21:50 +08:00
notification_spec.rb Fix weird test failure. 2017-03-20 12:06:37 +08:00
optimized_image_spec.rb SECURITY: protect upload params, only allow very strict filenames 2016-12-19 10:16:18 +11:00
permalink_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
plugin_store_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
post_action_spec.rb rename topic_status_update to topic_timer 2017-05-11 18:27:53 -04:00
post_action_type_spec.rb Enums that are used in tables need to be stable 2016-01-08 20:43:11 +05:30
post_analyzer_spec.rb FIX: don't extract links from .elided parts 2016-12-05 15:19:15 +01:00
post_detail_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
post_mover_spec.rb FIX: Copy post actions when moving a topic. 2017-04-06 12:16:22 +08:00
post_reply_spec.rb FIX: Update post replies when we move posts. (#4324) 2016-07-13 17:34:21 +02:00
post_spec.rb Minor cleanup of `/users/` rename 2017-03-30 10:23:24 -04:00
post_timing_spec.rb remove rails-observers 2016-12-22 16:46:53 +11:00
post_upload_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
queued_post_spec.rb Enums that are used in tables need to be stable 2016-01-08 20:43:11 +05:30
quoted_post_spec.rb FIX: don't raise exception when a quote was already extracted 2016-11-30 17:18:34 +01:00
remote_theme_spec.rb FEATURE: support uploads for themes 2017-05-10 15:47:11 -04:00
report_spec.rb FIX: admin dashboard posts count should not include system posts and whispers 2017-02-21 14:45:41 -05:00
rtl_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
s3_region_site_setting_spec.rb FEATURE: Add AWS S3 EU (London) "eu-west-2" region 2017-04-12 10:38:17 -04:00
screened_email_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
screened_ip_address_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
screened_url_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
site_setting_spec.rb PERF: Don't calculate the same query twice. 2016-11-24 14:05:26 +08:00
site_spec.rb FEATURE: Native theme support 2017-04-12 10:53:49 -04:00
stylesheet_cache_spec.rb FEATURE: out-of-the-box dark/light user selectable themes 2017-05-03 11:31:33 -04:00
tag_spec.rb add the spec for unused tag count 2016-10-28 16:14:20 -04:00
tag_user_spec.rb remove rails-observers 2016-12-22 16:46:53 +11:00
theme_field_spec.rb improve upload functionality 2017-05-10 15:47:11 -04:00
theme_spec.rb REFACTOR: upload workflow creation into UploadCreator 2017-05-11 00:16:57 +02:00
top_menu_item_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
top_topic_spec.rb FEATURE: make top criteria formula multipliers controlled by site 2016-01-21 10:30:06 +05:30
topic_allowed_user_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
topic_converter_spec.rb FIX: Private message can be set to publish in the future. 2017-04-11 20:44:25 +08:00
topic_embed_spec.rb FIX: More errors with non-ascii URLs 2017-03-07 11:21:41 -05:00
topic_featured_users_spec.rb FIX: If posts are deleted they should be updated in consistency jobs 2016-06-21 13:05:56 -04:00
topic_invite_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
topic_link_click_spec.rb FIX: Support links with google analytics tracking and hashes 2016-08-23 12:13:31 -04:00
topic_link_spec.rb Convert server side paths to use `/u/` 2017-03-30 10:23:24 -04:00
topic_list_spec.rb Remove old test case. 2017-05-22 18:23:09 +08:00
topic_participants_summary_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
topic_posters_summary_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
topic_spec.rb REFACTOR: Clean up some code associated with topic timers. 2017-05-22 18:10:29 +08:00
topic_timer_spec.rb REFACTOR: Clean up some code associated with topic timers. 2017-05-22 18:10:29 +08:00
topic_tracking_state_spec.rb FIX: whisper no longer experimental 2016-12-02 17:03:31 +11:00
topic_user_spec.rb PERF: improve performance of unread queries 2017-05-25 15:07:30 -04:00
topic_view_item_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
translation_override_spec.rb FIX: Allow message format translations to be overridden 2016-04-08 14:49:50 -04:00
trust_level3_requirements_spec.rb remove UserActionObserver, replace with after_save and service 2016-12-22 16:46:53 +11:00
twitter_user_info_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
unsubscribe_key_spec.rb FEATURE: simpler and friendlier unsubscribe workflow 2016-06-17 11:28:49 +10:00
upload_spec.rb REFACTOR: upload workflow creation into UploadCreator 2017-05-11 00:16:57 +02:00
user_action_spec.rb FIX: Do not update user stats like counts for private messages. 2017-01-16 11:07:53 +08:00
user_api_key_spec.rb FEATURE: user API now contains scopes so permission is granular 2016-10-14 16:05:42 +11:00
user_archived_message_spec.rb FEATURE: don't move muted messages back into inbox 2016-02-15 10:56:39 +11:00
user_auth_token_spec.rb FIX: Improve token rotation and increase logging 2017-03-07 13:27:43 -05:00
user_avatar_spec.rb FEATURE: Import facebook avatars when logging in via facebook 2016-09-19 15:10:23 +10:00
user_badge.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
user_history_spec.rb Enums that are used in tables need to be stable 2016-01-08 20:43:11 +05:30
user_open_id_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
user_option_spec.rb FIX: ensure consistency of user options 2016-03-17 10:03:56 +11:00
user_profile_spec.rb Revert "FIX: User website allows new TLDs" 2017-04-18 13:18:51 +05:30
user_profile_view_spec.rb FIX: Don't track user profile view when viewed by system user. 2016-08-23 16:25:31 +08:00
user_search_spec.rb FEATURE: allow user search API to restrict to group 2017-02-09 18:45:39 -05:00
user_spec.rb Support Ruby 2.4. 2017-04-15 12:29:00 +08:00
user_stat_spec.rb PERF: improve performance of unread queries 2017-05-25 15:07:30 -04:00
user_summary_spec.rb SECURITY: user summary could show topic links you have no permissions to 2016-01-28 11:12:12 +11:00
user_visit_spec.rb fix intermittent spec failure due to Time comparison with TimeWithZone 2017-02-17 10:30:29 -05:00
username_validator_spec.rb Prepare for separation of RSpec helper files 2015-12-01 20:39:42 +00:00
web_hook_event_spec.rb FEATURE: Webhooks. 2016-09-05 18:44:00 +08:00
web_hook_spec.rb Require `Sidekiq::Testing` in rails helper. 2017-03-29 11:10:25 +08:00