Skip to content

Commit

Permalink
Merge pull request #1085 from PlanoramaEvents/plan-1010-speed-up-sess…
Browse files Browse the repository at this point in the history
…ion-query

PLAN-1010 Speed up the query time for session retreival
  • Loading branch information
Gailbear authored Jun 22, 2024
2 parents 053c2a6 + bfb5da3 commit c8037a2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
30 changes: 20 additions & 10 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,15 @@ def references
]
end

# def eager_load
# [
# # {session_areas: :area},
# # :areas,
# # :published_session,
# # {taggings: :tag}
# ]
# end

def eager_load
[
{session_areas: :area},
# :areas,
# :published_session,
# {taggings: :tag}
]
end

def array_col?(col_name:)
return true if col_name == 'area_list'
Expand All @@ -254,6 +255,7 @@ def array_table(col_name:)

def join_tables
sessions = Arel::Table.new(Session.table_name)
published_sessions = Arel::Table.new(PublishedSession.table_name)

subquery = Session.area_list.as('areas_list')
tags_subquery = Session.tags_list_table.as('tags_list_table')
Expand Down Expand Up @@ -286,6 +288,13 @@ def join_tables
sessions.create_on(
conflict_counts[:session_id].eq(sessions[:id])
)
),
sessions.create_join(
published_sessions,
sessions.create_on(
published_sessions[:session_id].eq(sessions[:id])
),
Arel::Nodes::OuterJoin
)
]

Expand Down Expand Up @@ -316,13 +325,14 @@ def join_tables
joins
end

def select_fields
def select_fields
Session.select(
::Session.arel_table[Arel.star],
'conflict_counts.conflict_count',
'areas_list.area_list',
'tags_list_table.tags_array',
'labels_list_table.labels_array'
'labels_list_table.labels_array',
'published_sessions.session_id as is_published'
)
end

Expand Down
6 changes: 5 additions & 1 deletion app/serializers/session_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ class SessionSerializer
end

attribute :is_published do |session|
session.published?
if session.has_attribute?(:is_published)
session.is_published != nil
else
session.published?
end
end

has_many :session_areas, lazy_load_data: true, serializer: SessionAreaSerializer,
Expand Down

0 comments on commit c8037a2

Please sign in to comment.