Skip to content

Commit

Permalink
Merge pull request #1141 from PlanoramaEvents/plan-1040-query-for-con…
Browse files Browse the repository at this point in the history
…flict-count

PLAN-1040 Adjusting the query for conflict count
  • Loading branch information
balen authored Jul 25, 2024
2 parents b07ed3c + f1454eb commit f2c1a89
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
3 changes: 2 additions & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ def join_tables
conflict_counts,
sessions.create_on(
conflict_counts[:session_id].eq(sessions[:id])
)
),
Arel::Nodes::OuterJoin
),
sessions.create_join(
published_sessions,
Expand Down
30 changes: 9 additions & 21 deletions app/models/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,32 +218,20 @@ def keep_interest_trail
end

def self.conflict_counts
sessions = Session.arel_table
conflicts = Conflicts::SessionConflict.arel_table
ignored_conflicts = ::IgnoredConflict.arel_table

sessions.project(
sessions[:id].as('session_id'),
conflicts.project(
conflicts[:session_id].as('session_id'),
conflicts[:session_id].count.as('conflict_count')
)
.join(conflicts, Arel::Nodes::OuterJoin)
.on(
sessions[:id].eq(conflicts[:session_id])
.or(
sessions[:id].eq(conflicts[:conflict_session_id])
.and(
conflicts[:conflict_type].not_eq('room_conflict')
.or(
conflicts[:conflict_type].eq('room_conflict')
.and(
conflicts[:session_start_time].not_eq(conflicts[:conflict_session_start_time])
)
.where(
conflicts[:conflict_type].not_eq('room_conflict')
.or(
conflicts[:conflict_type].eq('room_conflict')
.and(
conflicts[:session_start_time].not_eq(conflicts[:conflict_session_start_time])
)
# .and(
# conflicts[:conflict_type].not_eq('person_schedule_conflict')
# .and(conflicts[:conflict_type].not_eq('person_back_to_back'))
# )
)
)
.and(
conflicts[:session_assignment_name].eq(nil).or(conflicts[:session_assignment_name].in(['Moderator', 'Participant', 'Invisible'])).and(
Expand All @@ -255,7 +243,7 @@ def self.conflict_counts
)
)
)
.group('sessions.id')
.group('session_conflicts.session_id')
end

def schedule_consistency
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/session_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class SessionSerializer

attribute :has_conflicts do |session|
if session.has_attribute?(:conflict_count)
session.conflict_count > 0
session.conflict_count && session.conflict_count > 0
else
(session.session_conflicts.count > 0) || (session.conflict_sessions.count > 0)
end
Expand Down

0 comments on commit f2c1a89

Please sign in to comment.