Merge pull request #6903 from CSammy/6152-tags-page-slow
Improve /tag page performance.
This commit is contained in:
commit
c53393c5de
4 changed files with 43 additions and 11 deletions
|
|
@ -166,6 +166,7 @@ The command will report queues that still have jobs and launch sidekiq process f
|
|||
* Correctly filter mentions on the server side [#6902](https://github.com/diaspora/diaspora/pull/6902)
|
||||
* Add aspects to the aspect membership dropdown when creating them on the getting started page [#6864](https://github.com/diaspora/diaspora/pull/6864)
|
||||
* Strip markdown from message preview in conversations list [#6923](https://github.com/diaspora/diaspora/pull/6923)
|
||||
* Improve tag stream performance [#6903](https://github.com/diaspora/diaspora/pull/6903)
|
||||
|
||||
## Features
|
||||
* Support color themes [#6033](https://github.com/diaspora/diaspora/pull/6033)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,16 @@ class Stream::Tag < Stream::Base
|
|||
end
|
||||
|
||||
def posts
|
||||
@posts ||= construct_post_query
|
||||
@posts ||= if user
|
||||
StatusMessage.user_tag_stream(user, tag.id)
|
||||
else
|
||||
StatusMessage.public_tag_stream(tag.id)
|
||||
end
|
||||
end
|
||||
|
||||
def stream_posts
|
||||
return [] unless tag
|
||||
super
|
||||
end
|
||||
|
||||
def tag_name=(tag_name)
|
||||
|
|
@ -42,13 +51,4 @@ class Stream::Tag < Stream::Base
|
|||
def publisher_opts
|
||||
{:open => true}
|
||||
end
|
||||
|
||||
def construct_post_query
|
||||
posts = if user.present?
|
||||
StatusMessage.owned_or_visible_by_user(user)
|
||||
else
|
||||
StatusMessage.all_public
|
||||
end
|
||||
posts.tagged_with(tag_name, :any => true)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -107,6 +107,18 @@ describe TagsController, :type => :controller do
|
|||
get :show, :name => 'foo', :format => :mobile
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it "returns the post with the correct age" do
|
||||
post2 = eve.post(
|
||||
:status_message,
|
||||
text: "#what #yes #hellyes #foo tagged second post",
|
||||
public: true,
|
||||
created_at: @post.created_at - 1.day
|
||||
)
|
||||
get :show, name: "what", max_time: @post.created_at, format: :json
|
||||
expect(JSON.parse(response.body).size).to be(1)
|
||||
expect(JSON.parse(response.body).first["guid"]).to eq(post2.guid)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -80,11 +80,30 @@ describe Stream::Tag do
|
|||
|
||||
describe 'shared behaviors' do
|
||||
before do
|
||||
@stream = Stream::Tag.new(FactoryGirl.create(:user), "test")
|
||||
@stream = Stream::Tag.new(FactoryGirl.create(:user), FactoryGirl.create(:tag).name)
|
||||
end
|
||||
it_should_behave_like 'it is a stream'
|
||||
end
|
||||
|
||||
describe '#stream_posts' do
|
||||
it "returns an empty array if the tag does not exist" do
|
||||
stream = Stream::Tag.new(FactoryGirl.create(:user), "test")
|
||||
expect(stream.stream_posts).to eq([])
|
||||
end
|
||||
|
||||
it "returns an empty array if there are no visible posts for the tag" do
|
||||
alice.post(:status_message, text: "#what", public: false, to: "all")
|
||||
stream = Stream::Tag.new(nil, "what")
|
||||
expect(stream.stream_posts).to eq([])
|
||||
end
|
||||
|
||||
it "returns the post containing the tag" do
|
||||
post = alice.post(:status_message, text: "#what", public: true)
|
||||
stream = Stream::Tag.new(FactoryGirl.create(:user), "what")
|
||||
expect(stream.stream_posts).to eq([post])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#tag_name=' do
|
||||
it 'downcases the tag' do
|
||||
stream = Stream::Tag.new(nil, "WHAT")
|
||||
|
|
|
|||
Loading…
Reference in a new issue