Merge pull request #4769 from Ruxton/feature/faster_stream_queries

Updating queries for the stream to be faster
This commit is contained in:
Jonne Haß 2014-02-09 16:25:11 +01:00
commit 4a3869cda8
4 changed files with 8 additions and 5 deletions

View file

@ -6,6 +6,7 @@
* Style improvements for SPV, use original author's avatar for reshares [#4754](https://github.com/diaspora/diaspora/issue/4754) * Style improvements for SPV, use original author's avatar for reshares [#4754](https://github.com/diaspora/diaspora/issue/4754)
* Update image branding to the new decided standard [#4702](https://github.com/diaspora/diaspora/pull/4702) * Update image branding to the new decided standard [#4702](https://github.com/diaspora/diaspora/pull/4702)
* Consistent naming of conversations and messages [#4756](https://github.com/diaspora/diaspora/pull/4756) * Consistent naming of conversations and messages [#4756](https://github.com/diaspora/diaspora/pull/4756)
* Improve stream generation time [#4769](https://github.com/diaspora/diaspora/pull/4769)
## Bug fixes ## Bug fixes

View file

@ -68,10 +68,8 @@ module User::Querying
end end
def construct_public_followings_sql(opts) def construct_public_followings_sql(opts)
aspects = Aspect.where(:id => opts[:by_members_of]) Rails.logger.debug("[EVIL-QUERY] user.construct_public_followings_sql")
person_ids = Person.connection.select_values(people_in_aspects(aspects).select("people.id").to_sql) query = opts[:klass].where(:author_id => Person.in_aspects(opts[:by_members_of]).select("people.id"), :public => true, :pending => false)
query = opts[:klass].where(:author_id => person_ids, :public => true, :pending => false)
unless(opts[:klass] == Photo) unless(opts[:klass] == Photo)
query = query.where(:type => opts[:type]) query = query.where(:type => opts[:type])

View file

@ -27,7 +27,7 @@ Diaspora::Application.configure do
# Log the query plan for queries taking more than this (works # Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL) # with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5 # config.active_record.auto_explain_threshold_in_seconds = 0.5
# Do not compress assets # Do not compress assets
config.assets.compress = false config.assets.compress = false

View file

@ -51,20 +51,24 @@ module EvilQuery
end end
def make_relation! def make_relation!
Rails.logger.debug("[EVIL-QUERY] make_relation!")
post_ids = aspects_post_ids! + ids!(followed_tags_posts!) + ids!(mentioned_posts) post_ids = aspects_post_ids! + ids!(followed_tags_posts!) + ids!(mentioned_posts)
post_ids += ids!(community_spotlight_posts!) if @include_spotlight post_ids += ids!(community_spotlight_posts!) if @include_spotlight
Post.where(:id => post_ids) Post.where(:id => post_ids)
end end
def aspects_post_ids! def aspects_post_ids!
Rails.logger.debug("[EVIL-QUERY] aspect_post_ids!")
@user.visible_shareable_ids(Post, :limit => 15, :order => "#{@order} DESC", :max_time => @max_time, :all_aspects? => true, :by_members_of => @user.aspect_ids) @user.visible_shareable_ids(Post, :limit => 15, :order => "#{@order} DESC", :max_time => @max_time, :all_aspects? => true, :by_members_of => @user.aspect_ids)
end end
def followed_tags_posts! def followed_tags_posts!
Rails.logger.debug("[EVIL-QUERY] followed_tags_posts!")
StatusMessage.public_tag_stream(@user.followed_tag_ids) StatusMessage.public_tag_stream(@user.followed_tag_ids)
end end
def mentioned_posts def mentioned_posts
Rails.logger.debug("[EVIL-QUERY] mentioned_posts")
StatusMessage.where_person_is_mentioned(@user.person) StatusMessage.where_person_is_mentioned(@user.person)
end end