Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 5ba274f

Browse files
authored
FIX: Change how we filter date for emotion on /filter (#1006)
1 parent 4ba7451 commit 5ba274f

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/sentiment/emotion_filter_order.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@ def self.register!(plugin)
1212
&.constraints
1313
&.flat_map(&:children)
1414
&.find do |node|
15-
node.is_a?(Arel::Nodes::Grouping) &&
16-
node.expr.to_s.match?(/topics\.bumped_at\s*>=/)
15+
node.is_a?(Arel::Nodes::BoundSqlLiteral) &&
16+
node.to_sql.match?(/topics\.bumped_at\s*>=/)
1717
end
18-
&.expr
19-
&.split(">=")
20-
&.last if scope.to_sql.include?("topics.bumped_at >=")
18+
&.positional_binds
19+
&.first if scope.to_sql.include?("topics.bumped_at >=")
2120

22-
# Fallback in case we can't find the scope period
23-
scope_period ||= "CURRENT_DATE - INTERVAL '1 year'"
21+
if scope_period.is_a?(ActiveSupport::TimeWithZone)
22+
scope_period = "'#{scope_period.to_date}'"
23+
else
24+
# Fallback in case we can't find the scope period
25+
scope_period = "CURRENT_DATE - INTERVAL '1 year'"
26+
end
2427

2528
emotion_clause = <<~SQL
2629
COUNT(*) FILTER (WHERE (classification_results.classification::jsonb->'#{emotion}')::float > 0.1)

0 commit comments

Comments
 (0)