huginn_datatable 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93c77acb3179b06e77712420af3deb4c8f595a715c45e3c4f00c03a5f4e8a73c
4
- data.tar.gz: a0dba33d0fffd18d0df9303d9253ec9652ab5620d6e77fbc0b017a3c8000b335
3
+ metadata.gz: c95231f872fd90d2d8dc0a3f351c5648c29cff6543985c95b0fc36ecc5b351c0
4
+ data.tar.gz: 6ccd8840db434f657619e278e98ff6024037e61258ea5115abaf463c33a7fde7
5
5
  SHA512:
6
- metadata.gz: 56699ffb963d5c809dc3664fbbc7456f39a634cd6952ad9472b8eb0f9f891016291baa859203a32d3024e7b496adc003c2f55ace6a384ce691c54b6adb37c715
7
- data.tar.gz: 2437df93a69e3328ae63b6be1fbb623c7a5784e0232d0bb1fa757a74698f9bad211da135459f27b5a879d9f0cbca02388372fa169f0acb7e6c947ed0693b9805
6
+ metadata.gz: 3b18e30b5af9d01f88e49b95f8971856418ebd327bc87a3c29a8c2b6d987a2f2fee9a35ab5c8726d294175d7ddcec281ecab09a238c28a69fc10afeb8abb3640
7
+ data.tar.gz: 9de963497c159849bc4b6d4e12fc73dca5219394288264802f7af63d1451c9c419d5ee39b8266fe5019bad0db291a660463ce64924800063fa1b34c33b21687d
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ### Unreleased
4
4
 
5
+ #### 0.5.0
6
+
7
+ - **Fix (changes results):** `range_data` on a datetime column now covers whole days. The dates were compared as midnight, so the last day was left out and a single-day range (`["2024-03-10", "2024-03-10"]`, which Arel turns into `= '2024-03-10'`) only matched rows created exactly at 00:00:00. Now `from` is the start of its day and `to` the end of its day, in `Time.zone`. Date and numeric columns are unchanged. If a caller compensated by sending the day after as `to`, drop that adjustment when upgrading, or the range will include one extra day.
8
+
9
+ #### 0.4.2
10
+
11
+ - **Performance (PostgreSQL):** association matches in `search` are written as `fk = ANY(ARRAY(SELECT DISTINCT ...))` instead of `fk IN (SELECT DISTINCT ...)`. The `IN` form was planned as a hashed SubPlan, which can't take part in a BitmapOr: a single association column (e.g. `searchable_columns :title, company: [:name]`) made the whole OR fall back to filtering every row, ignoring the GIN trigram/tsvector indexes. `ANY(ARRAY(...))` runs once as an InitPlan and keeps the index plan (measured on 20k-30k rows: ~500 ms → ~1 ms for a selective term). Results are unchanged; other adapters keep `IN`.
12
+
5
13
  #### 0.4.1
6
14
 
7
15
  - **Fix:** the specs no longer use the Ruby 3.1+ shorthand hash syntax (`f(allowed_paths:)`), so the suite loads again on Ruby 3.0 (the gem's minimum). No library code changed from 0.4.0.
data/README.md CHANGED
@@ -131,7 +131,7 @@ Supported params:
131
131
  | `page`, `per_page` | Pagination (clamped to `pagy_max_items`) |
132
132
  | `search` | Delegates to `Huginn::Searchable.search` |
133
133
  | `filters` | Hash (`{ "col" => v }` or `{ "col" => [a, b] }`) / Array of hashes / pairs -> exact or `IN` conditions (`"col" => "null"` → `IS NULL`) |
134
- | `range_data` | `{ "created_at" => ["2024-01-01", "2024-12-31"] }` — date or numeric ranges |
134
+ | `range_data` | `{ "created_at" => ["2024-01-01", "2024-12-31"] }` — date or numeric ranges, both ends inclusive (on a datetime column the dates cover whole days) |
135
135
  | `orders` | `[{ "pessoa.nome" => "desc" }]` — plain or association-scoped columns |
136
136
 
137
137
  ### Array columns (PostgreSQL)
data/README.pt-BR.md CHANGED
@@ -131,7 +131,7 @@ Parâmetros suportados:
131
131
  | `page`, `per_page` | Paginação (limitada a `pagy_max_items`) |
132
132
  | `search` | Delega para `Huginn::Searchable.search` |
133
133
  | `filters` | Hash (`{ "col" => v }` ou `{ "col" => [a, b] }`) / Array de hashes / pares -> condições exatas ou `IN` (`"col" => "null"` → `IS NULL`) |
134
- | `range_data` | `{ "created_at" => ["2024-01-01", "2024-12-31"] }` — ranges de datas ou numéricos |
134
+ | `range_data` | `{ "created_at" => ["2024-01-01", "2024-12-31"] }` — ranges de datas ou numéricos, com as duas pontas inclusivas (numa coluna datetime as datas valem pelo dia inteiro) |
135
135
  | `orders` | `[{ "pessoa.nome" => "desc" }]` — colunas simples ou de associação |
136
136
 
137
137
  ### Colunas array (PostgreSQL)
@@ -221,6 +221,8 @@ module Huginn
221
221
  to = parse_datatable_date(to)
222
222
  return relation if from.blank? && to.blank?
223
223
 
224
+ # Dates are compared as whole days: on a datetime column, "to" covers its last day.
225
+ from, to = from&.beginning_of_day, to&.end_of_day if type == :datetime
224
226
  relation.where(range_predicate(attr, from, to))
225
227
  end
226
228
  end
@@ -108,6 +108,7 @@ module Huginn
108
108
  # belongs_to -> base[fk] IN (SELECT DISTINCT t1[join_pk] FROM t1 ...)
109
109
  # has_many -> base[pk] IN (SELECT DISTINCT t1[fk] FROM t1 ...)
110
110
  #
111
+ # On PostgreSQL the membership is written as `= ANY(ARRAY(...))` (see #member_of).
111
112
  # Walks the chain from the first target table outwards so the base table
112
113
  # is never scanned inside the subquery.
113
114
  def anchored_predicate(path, attrs)
@@ -139,7 +140,20 @@ module Huginn
139
140
  manager.project(projection)
140
141
  manager.distinct
141
142
 
142
- outer.in(manager)
143
+ member_of(outer, manager)
144
+ end
145
+
146
+ # `column IN (subquery)` becomes a hashed SubPlan on PostgreSQL, which can't
147
+ # take part in a BitmapOr: one association arm then forces the whole search
148
+ # (every column OR'ed together) into a filter over every row of the table,
149
+ # ignoring the GIN indexes. `column = ANY(ARRAY(subquery))` is evaluated
150
+ # once as an InitPlan and the column's index is used, so the OR stays a
151
+ # BitmapOr. Other adapters keep the plain IN.
152
+ def member_of(column, subquery)
153
+ return column.in(subquery) unless postgresql?
154
+
155
+ array = Arel::Nodes::NamedFunction.new("ARRAY", [subquery.ast])
156
+ Arel::Nodes::Equality.new(column, Arel::Nodes::NamedFunction.new("ANY", [array]))
143
157
  end
144
158
 
145
159
  # Whether the first hop goes through a join model; the FK anchoring is
@@ -161,7 +175,7 @@ module Huginn
161
175
  .distinct
162
176
 
163
177
  predicate = fuzzy_predicates(attrs).reduce(&:or)
164
- arel_table[primary_key].in(base.joins(spec).where(predicate).arel)
178
+ member_of(arel_table[primary_key], base.joins(spec).where(predicate).arel)
165
179
  end
166
180
 
167
181
  def fuzzy_predicate(attr)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Huginn
4
- VERSION = "0.4.1"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: huginn_datatable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kayky Marcelo