Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fast page + eager load on conversation list , conversation and predic… #948

Merged
merged 1 commit into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ gem "ruby-oembed"
gem "mustache"

gem "chronic", "~> 0.10.2"
gem "fast_page", "~> 0.1.5"
gem "kaminari", "~> 1.2"

gem "timezone", "~> 1.2"
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ GEM
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
fast_page (0.1.5)
activerecord
activesupport
ffi (1.15.5)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
Expand Down Expand Up @@ -695,6 +698,7 @@ DEPENDENCIES
factory_bot_rails
faker!
faraday
fast_page (~> 0.1.5)
friendly_id (~> 5.2)
geocoder (~> 1.6)
geoip
Expand Down
2 changes: 2 additions & 0 deletions app/graphql/mutations/predicates/search_predicate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def app_users(per, page)
@app_users = @segment.execute_query
.page(page)
.per(per)
.fast_page
.includes(taggings: :tags)
end

argument :app_key, String, required: true
Expand Down
4 changes: 2 additions & 2 deletions app/graphql/types/app_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def conversations(per:, page:, filter:, sort:, agent_id: nil, tag: nil, term: ni
end

@collection = filter_by_agent(agent_id) if agent_id.present?
@collection = @collection.page(page).per(per)
@collection = @collection.page(page).per(per).fast_page
sort_conversations(sort)
@collection = @collection.tagged_with(tag) if tag.present?
if term
Expand All @@ -277,7 +277,7 @@ def conversations(per:, page:, filter:, sort:, agent_id: nil, tag: nil, term: ni
).result
end

@collection
@collection.includes(assignee: { avatar_attachment: :blob }, latest_message: { authorable: { avatar_attachment: :blob } })
end

def conversations_counts
Expand Down
4 changes: 4 additions & 0 deletions app/graphql/types/app_user_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def kind

field :tag_list, [String], null: true

def tag_list
object.tags.collect(&:name)
end

def state
object.subscription_state
end
Expand Down
2 changes: 2 additions & 0 deletions app/graphql/types/conversation_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ def last_message

def messages(per:, page:)
@collection = object.messages
.includes(:message_block, :message_event, :message_content, authorable: { avatar_attachment: :blob })
.order("id desc")
.page(page)
.per(per)
.fast_page
end
end
end
2 changes: 2 additions & 0 deletions app/models/conversation_part.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class ConversationPart < ApplicationRecord
belongs_to :authorable, polymorphic: true, optional: true

belongs_to :message_block, class_name: "ConversationPartBlock", foreign_key: :messageable_id, optional: true
belongs_to :message_event, class_name: "ConversationPartEvent", foreign_key: :messageable_id, optional: true
belongs_to :message_content, class_name: "ConversationPartContent", foreign_key: :messageable_id, optional: true

# has_one :conversation_part_content, dependent: :destroy

Expand Down