FIX: Change how we filter date for emotion on /filter (#1006)

This commit is contained in:
Rafael dos Santos Silva 2024-12-05 14:10:12 -03:00 committed by GitHub
parent 4ba74511c2
commit 5ba274f7a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 7 deletions

View File

@ -12,15 +12,18 @@ module DiscourseAi
&.constraints
&.flat_map(&:children)
&.find do |node|
node.is_a?(Arel::Nodes::Grouping) &&
node.expr.to_s.match?(/topics\.bumped_at\s*>=/)
node.is_a?(Arel::Nodes::BoundSqlLiteral) &&
node.to_sql.match?(/topics\.bumped_at\s*>=/)
end
&.expr
&.split(">=")
&.last if scope.to_sql.include?("topics.bumped_at >=")
&.positional_binds
&.first if scope.to_sql.include?("topics.bumped_at >=")
if scope_period.is_a?(ActiveSupport::TimeWithZone)
scope_period = "'#{scope_period.to_date}'"
else
# Fallback in case we can't find the scope period
scope_period ||= "CURRENT_DATE - INTERVAL '1 year'"
scope_period = "CURRENT_DATE - INTERVAL '1 year'"
end
emotion_clause = <<~SQL
COUNT(*) FILTER (WHERE (classification_results.classification::jsonb->'#{emotion}')::float > 0.1)