discourse/app/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
..
concerns remove rails-observers 2016-12-22 16:46:53 +11:00
about.rb Add scope for human users. 2017-03-11 14:25:09 +08:00
admin_dashboard_data.rb Use && and || consistently so that there's less chance of copy paste errors in the future 2017-02-15 00:25:49 -08:00
api_key.rb
application_request.rb cut out an exception 2015-08-19 16:57:26 +10:00
auto_track_duration_site_setting.rb fix the build 2015-09-14 10:48:24 +02:00
backup.rb FIX: log backups download/destroy staff action 2017-01-16 19:53:31 +01:00
badge_grouping.rb annotate models 2016-02-23 10:33:53 +11:00
badge_type.rb annotate models 2016-02-23 10:33:53 +11:00
badge.rb Change Anniversary badge to be multiple grant, once per year 2017-04-28 14:22:54 -04:00
category_and_topic_lists.rb FEATURE: new 'categories_and_latest' endpoint 2016-08-29 22:47:44 +02:00
category_custom_field.rb
category_featured_topic.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.rb Support Ruby 2.4. 2017-04-15 12:29:00 +08:00
category_group.rb FEATURE: Log staff actions for Category changes. 2015-09-18 10:53:08 +08:00
category_list.rb FEATURE: each category can control how many topics to show on categories page 2017-03-01 15:12:57 -05:00
category_page_style.rb UX: new 'category_page_style' site setting 2016-08-22 23:01:43 +02:00
category_search_data.rb
category_tag_group.rb annotate models 2016-06-17 11:28:49 +10:00
category_tag.rb annotate models 2016-06-17 11:28:49 +10:00
category_user.rb FIX: Couldn't update category notification level 2016-08-02 11:22:02 -04:00
category.rb rename topic_status_update to topic_timer 2017-05-11 18:27:53 -04:00
child_theme.rb FEATURE: Native theme support 2017-04-12 10:53:49 -04:00
color_scheme_color.rb annotate models 2016-02-23 10:33:53 +11:00
color_scheme.rb FIX: emails should use default theme colors 2017-05-03 14:35:13 -04:00
custom_emoji.rb Update annotations. 2017-03-22 14:26:53 +08:00
developer.rb missing annotation 2016-08-15 17:59:36 +10:00
digest_email_site_setting.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.rb annotate models 2016-10-31 15:02:11 +05:30
discourse_single_sign_on.rb FIX: require re-activation if SSO changes email and updates it 2017-05-16 16:18:18 -04:00
discourse_version_check.rb FEATURE: Installed Version link shows GitHub Compare to branch being followed 2016-08-02 06:18:44 -04:00
draft_sequence.rb Support Ruby 2.4. 2017-04-15 12:29:00 +08:00
draft.rb annotate models 2016-02-23 10:33:53 +11:00
email_change_request.rb FIX: Don't allow invalid email to be saved. 2016-12-21 17:47:11 +08:00
email_log.rb FIX: don't apply max_emails_per_day_per_user on critical emails 2017-05-03 17:07:39 +05:30
email_token.rb FEATURE: remove email_token_grace_period_hours 2016-12-19 17:15:20 +11:00
embeddable_host.rb annotate models 2017-05-12 14:47:08 -04:00
embedding.rb FEATURE: Setting to poll feeds more frequently 2017-05-10 14:30:12 -04:00
emoji_set_site_setting.rb FIX: Emoji update job was not being queued 2016-07-25 12:11:36 -04:00
emoji.rb FIX: unescape emoji in pretty title 2017-05-15 10:28:05 -04:00
facebook_user_info.rb annotate models 2016-10-31 15:02:11 +05:30
github_user_info.rb annotate models 2016-02-23 10:33:53 +11:00
given_daily_like.rb annotate models 2016-03-28 15:21:45 +11:00
global_setting.rb correct logic, so revalidation is reset 2017-03-13 10:47:43 -04:00
google_user_info.rb annotate models 2016-02-23 10:33:53 +11:00
group_archived_message.rb FEATURE: move_to_inbox and archive_message events 2017-02-28 09:56:41 -05:00
group_custom_field.rb
group_history.rb FEATURE: Group logs. 2016-12-12 17:29:54 +08:00
group_manager.rb update annotations 2015-09-18 10:41:10 +10:00
group_mention.rb Update annotate and annotate models 2016-01-11 17:30:56 +11:00
group_user.rb FEATURE: default notification level for group messages 2017-04-20 15:47:35 -04:00
group.rb fix build (cc @tgxworld) 2017-05-05 13:13:49 +02:00
incoming_domain.rb FIX: If the host can't be extracted don't raise an error 2017-05-04 13:26:37 -04:00
incoming_email.rb annotate models 2016-05-30 10:45:32 +10:00
incoming_link.rb
incoming_links_report.rb FIX: broken links on admin dashboard in Top Referrers section 2016-02-22 14:31:13 -05:00
incoming_referer.rb
instagram_user_info.rb annotate models 2016-03-28 15:21:45 +11:00
invite_redeemer.rb FIX: always send password reset email when accepting invite if password is not set 2017-04-18 14:37:06 +05:30
invite.rb FIX: rescue specific errors on invite failure 2017-05-02 15:13:33 +05:30
invited_group.rb
like_notification_frequency_site_setting.rb FEATURE: like notification frequency of never 2016-03-06 09:12:59 +11:00
locale_site_setting.rb Add locale step 2016-09-22 09:52:19 -04:00
mailing_list_mode_site_setting.rb Remove daily mailing mode option as it doesn't scale. 2017-05-05 12:21:50 +08:00
muted_user.rb update annotations 2015-09-18 10:41:10 +10:00
new_topic_duration_site_setting.rb fix the build 2015-09-14 10:48:24 +02:00
notification_level_when_replying_site_setting.rb FEATURE: Add normal as a preference for topic subscription state when replying to a topic 2017-04-20 22:33:10 -04:00
notification.rb FEATURE: staff can set a timer to remind them about a topic 2017-05-16 14:49:50 -04:00
oauth2_user_info.rb annotate models 2016-02-23 10:33:53 +11:00
onceoff_log.rb annotate models 2016-05-30 10:45:32 +10:00
optimized_image.rb Refactor FileHelper to use keyword arguments. 2017-05-24 13:54:26 -04:00
permalink.rb FIX: permalinks redirect on subfolder installs could add the subfolder to the url twice 2015-10-12 16:54:53 -04:00
plugin_store_row.rb annotate models 2016-02-23 10:33:53 +11:00
plugin_store.rb Support Ruby 2.4. 2017-04-15 12:29:00 +08:00
post_action_type.rb remove rails-observers 2016-12-22 16:46:53 +11:00
post_action.rb rename topic_status_update to topic_timer 2017-05-11 18:27:53 -04:00
post_analyzer.rb Convert front end paths from /users/ to /u/ 2017-03-30 10:23:24 -04:00
post_custom_field.rb update annotations 2015-09-18 10:41:10 +10:00
post_detail.rb annotate models 2016-02-23 10:33:53 +11:00
post_mover.rb PostReply doesn't have a primary key, so no luck here 2017-04-24 23:14:01 +02:00
post_reply.rb FIX: Update post replies when we move posts. (#4324) 2016-07-13 17:34:21 +02:00
post_revision.rb remove rails-observers 2016-12-22 16:46:53 +11:00
post_search_data.rb annotate models 2016-02-23 10:33:53 +11:00
post_stat.rb update annotations 2015-09-18 10:41:10 +10:00
post_timing.rb FEATURE: track user visits on mobile and display on admin dashboard in a new Mobile section 2015-07-07 14:06:42 -04:00
post_upload.rb Update annotations. 2016-11-24 10:13:03 +08:00
post.rb FIX: when searching PMs also search group PMs 2017-05-11 15:59:03 -04:00
previous_replies_site_setting.rb FEATURE: allow users to control how many previous replies they get 2016-02-19 13:57:07 +11:00
queued_post.rb FIX: Polls permanently broken if post requires approval. 2017-01-26 13:29:43 +08:00
quoted_post.rb FIX: don't raise exception when a quote was already extracted 2016-11-30 17:18:34 +01:00
remote_theme.rb REFACTOR: upload workflow creation into UploadCreator 2017-05-11 00:16:57 +02:00
report.rb FIX: Don't show category options for reports that can't be scoped to a category. 2017-04-13 17:10:55 +08:00
rtl.rb Add initial Urdu support with RTL direction 2016-12-03 23:17:51 -05:00
s3_region_site_setting.rb FEATURE: Add AWS S3 EU (London) "eu-west-2" region 2017-04-12 10:38:17 -04:00
scheduler_stat.rb purge scheduler_stats every 1 month instead of 3 2017-04-28 15:05:15 -07:00
screened_email.rb annotate models 2016-02-23 10:33:53 +11:00
screened_ip_address.rb SECURITY: Possible SQL injection. 2016-07-18 15:35:41 +08:00
screened_url.rb annotate models 2016-02-23 10:33:53 +11:00
single_sign_on_record.rb annotate models 2016-10-31 15:02:11 +05:30
site_setting.rb PERF: Don't calculate the same query twice. 2016-11-24 14:05:26 +08:00
site.rb PERF: avoid query as admin 2017-05-12 11:09:41 -04:00
slug_setting.rb
stylesheet_cache.rb FEATURE: Native theme support 2017-04-12 10:53:49 -04:00
tag_group_membership.rb annotate models 2016-06-17 11:28:49 +10:00
tag_group.rb annotate models 2016-06-17 11:28:49 +10:00
tag_user.rb FEATURE: improved tag and category watching and tracking 2016-07-08 12:58:30 +10:00
tag.rb FIX: Tags used only on deleted topics could not be used again 2016-10-28 15:11:50 -04:00
theme_field.rb FEATURE: support uploads for themes 2017-05-10 15:47:11 -04:00
theme.rb FEATURE: support uploads for themes 2017-05-10 15:47:11 -04:00
top_lists.rb
top_menu_item.rb
top_topic.rb PERF: Don't calculate the same query twice. 2016-11-24 14:05:26 +08:00
topic_allowed_group.rb
topic_allowed_user.rb
topic_converter.rb FIX: Private message can be set to publish in the future. 2017-04-11 20:44:25 +08:00
topic_custom_field.rb annotate models 2016-05-30 10:45:32 +10:00
topic_embed.rb FIX: make TopicEmbed trashable 2017-04-25 18:40:39 +05:30
topic_featured_users.rb FIX: If posts are deleted they should be updated in consistency jobs 2016-06-21 13:05:56 -04:00
topic_invite.rb
topic_link_click.rb FIX: Support links with google analytics tracking and hashes 2016-08-23 12:13:31 -04:00
topic_link.rb just checking for existence is enough here 2016-11-30 23:41:07 +01:00
topic_list.rb FIX: N+1 query in suggested topics list. 2017-05-22 18:05:38 +08:00
topic_notifier.rb FEATURE: notification_level on a per-group basis 2015-12-14 23:17:09 +01:00
topic_participants_summary.rb FEATURE: primary group class on avatars in topic list 2017-02-20 15:55:10 -05:00
topic_poster.rb FEATURE: primary group class on avatars in topic list 2017-02-20 15:55:10 -05:00
topic_posters_summary.rb FEATURE: primary group class on avatars in topic list 2017-02-20 15:55:10 -05:00
topic_tag.rb annotate models 2016-05-30 10:45:32 +10:00
topic_timer.rb FEATURE: staff can set a timer to remind them about a topic 2017-05-16 14:49:50 -04:00
topic_tracking_state.rb PERF: improve performance of unread queries 2017-05-25 15:07:30 -04:00
topic_user.rb PERF: improve performance of unread queries 2017-05-25 15:07:30 -04:00
topic_view_item.rb Update annotations. 2017-03-22 14:26:53 +08:00
topic.rb PERF: improve performance of unread queries 2017-05-25 15:07:30 -04:00
translation_override.rb annotate models 2016-05-30 10:45:32 +10:00
trust_level_setting.rb fix the build 2015-09-14 10:48:24 +02:00
trust_level3_requirements.rb FEATURE: add caps to trust level 3 requirements for posts read and topics viewed, configurable in settings 2016-05-25 14:55:49 -04:00
twitter_user_info.rb annotate models 2016-02-23 10:33:53 +11:00
unsubscribe_key.rb FEATURE: configure session time via site setting for all the users (#4343) 2016-07-23 02:57:30 +05:30
upload.rb Refactor FileHelper to use keyword arguments. 2017-05-24 13:54:26 -04:00
user_action.rb Convert server side paths to use /u/ 2017-03-30 10:23:24 -04:00
user_api_key.rb annotate models 2016-10-31 15:02:11 +05:30
user_archived_message.rb FEATURE: move_to_inbox and archive_message events 2017-02-28 09:56:41 -05:00
user_auth_token_log.rb Update annotations. 2017-03-22 14:26:53 +08:00
user_auth_token.rb Update annotations. 2017-03-22 14:26:53 +08:00
user_avatar.rb FIX: Don't rate limit gravatar downloads 2017-05-24 13:54:26 -04:00
user_badge.rb annotate models 2016-02-23 10:33:53 +11:00
user_badges.rb FEATURE: you can not drill down and see why you have badges 2016-01-18 17:59:20 +11:00
user_custom_field.rb
user_export.rb PERF: stream CSV exports so they don't fail when they are too big 2016-05-25 22:20:35 +02:00
user_field_option.rb annotate models 2016-02-23 10:33:53 +11:00
user_field.rb remove rails-observers 2016-12-22 16:46:53 +11:00
user_history.rb FEATURE: Native theme support 2017-04-12 10:53:49 -04:00
user_open_id.rb annotate models 2016-02-23 10:33:53 +11:00
user_option.rb FEATURE: allow users to select theme on single device 2017-05-15 12:48:16 -04:00
user_profile_view.rb FIX: Don't track user profile view when viewed by system user. 2016-08-23 16:25:31 +08:00
user_profile.rb FIX: Don't incluide a trailing <br> in the bio excerpt 2017-05-18 16:40:07 -04:00
user_search_data.rb
user_search.rb FEATURE: allow user search API to restrict to group 2017-02-09 18:45:39 -05:00
user_stat.rb PERF: improve performance of unread queries 2017-05-25 15:07:30 -04:00
user_summary.rb FIX: most liked queries were leaking info in user summaries 2016-05-30 19:48:46 +02:00
user_visit.rb FEATURE: filter admin reports via user group 2016-02-04 11:23:49 +05:30
user_warning.rb FEATURE: default notification level for group messages 2017-04-20 15:47:35 -04:00
user.rb FIX: send activation email when accepting invite if password is set 2017-04-15 14:59:50 +05:30
username_validator.rb FIX: Don't allow invalid email to be saved. 2016-12-21 17:47:11 +08:00
web_hook_event_type.rb FEATURE: Webhook for user creation and approval 2016-09-19 10:12:55 +08:00
web_hook_event.rb annotate models 2016-10-31 15:02:11 +05:30
web_hook.rb FIX: Add web hook DiscourseEvents in initializer. 2017-04-12 11:55:49 +08:00