rollups 0.3.2 → 0.4.1

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: 0e5c6fead572e785077c4ab0afd4e627dd152580a5f7d06dfaec55cca368892f
4
- data.tar.gz: c48a223298b96a5404fda29192f6453e92f6f00fe10b53db5dfc633fe46696c8
3
+ metadata.gz: 98d29255d1ec08a3ca9e7db462c8157b3c87056ffc2258c785bc768e87d1afaa
4
+ data.tar.gz: 1810ec099cb09c935de19a415e17bca8842f7d0a2cd5d1ecc5bbb5dc51c2b514
5
5
  SHA512:
6
- metadata.gz: d831822c3b6c4b70d119a2bcd704ae579d8f444cf7ffce388842aa5fc7841d0435669a203b9c54a55629088dfb553ead3288a6282d9f4ea5d5b9b9f737222086
7
- data.tar.gz: af477019c11b0a75548d4181e7cf693d75487565ab99dd4b469bc3d748902d0cb802f2f868509cc71eb914e37796a435b013bbcc42a82a3189f9be0779b43c19
6
+ metadata.gz: efdd0f38f818d3bef2cce27554b3b84e104b78f1844475b334273cbf81c3fbea0ebe7a2b37ae394eae9b429e4f7a687b6ee901ab286c6981aa5c177fec92a8f4
7
+ data.tar.gz: a6e0c406ccc598c3a070cf4819eef7d3cecb8ae761f825fe41580d21a95535f5c3c83c6b24569484be31865eba6dd36a0084c467a3f9324b5aa57b544040ad4c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 0.4.1 (2024-10-07)
2
+
3
+ - Fixed connection leasing for Active Record 7.2+
4
+
5
+ ## 0.4.0 (2024-10-01)
6
+
7
+ - Added support for Active Record 8
8
+ - Dropped support for Ruby < 3.1 and Active Record < 7
9
+
1
10
  ## 0.3.2 (2024-02-09)
2
11
 
3
12
  - Fixed incorrect rollups with `time_zone: false` when `Rollup.time_zone` has a negative UTC offset
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020-2023 Andrew Kane
3
+ Copyright (c) 2020-2024 Andrew Kane
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  Works great with [Ahoy](https://github.com/ankane/ahoy) and [Searchjoy](https://github.com/ankane/searchjoy)
6
6
 
7
- [![Build Status](https://github.com/ankane/rollup/workflows/build/badge.svg?branch=master)](https://github.com/ankane/rollup/actions)
7
+ [![Build Status](https://github.com/ankane/rollup/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/rollup/actions)
8
8
 
9
9
  ## Installation
10
10
 
@@ -14,12 +14,6 @@ Add this line to your application’s Gemfile:
14
14
  gem "rollups"
15
15
  ```
16
16
 
17
- For Rails < 6, also add:
18
-
19
- ```ruby
20
- gem "activerecord-import"
21
- ```
22
-
23
17
  And run:
24
18
 
25
19
  ```sh
@@ -29,7 +29,7 @@ class Rollup
29
29
  def validate_column(column)
30
30
  unless column.is_a?(Symbol) || column.is_a?(Arel::Nodes::SqlLiteral)
31
31
  column = column.to_s
32
- unless /\A\w+(\.\w+)?\z/i.match(column)
32
+ unless /\A\w+(\.\w+)?\z/i.match?(column)
33
33
  raise ActiveRecord::UnknownAttributeReference, "Query method called with non-attribute argument(s): #{column.inspect}. Use Arel.sql() for known-safe values."
34
34
  end
35
35
  end
@@ -119,9 +119,9 @@ class Rollup
119
119
 
120
120
  # removing starting and ending quotes
121
121
  # for simplicity, they don't need to be the same
122
- value = value[1..-2] if value.match(/\A["'`].+["'`]\z/)
122
+ value = value[1..-2] if value.match?(/\A["'`].+["'`]\z/)
123
123
 
124
- unless value.match(/\A\w+\z/)
124
+ unless value.match?(/\A\w+\z/)
125
125
  raise "Cannot determine dimension name: #{group}. Use the dimension_names option"
126
126
  end
127
127
 
@@ -191,6 +191,12 @@ class Rollup
191
191
  conflict_target << :dimensions if Utils.dimensions_supported?
192
192
 
193
193
  options = Utils.mysql? ? {} : {unique_by: conflict_target}
194
+ if ActiveRecord::VERSION::MAJOR >= 8
195
+ utc = ActiveSupport::TimeZone["Etc/UTC"]
196
+ records.each do |v|
197
+ v[:time] = v[:time].in_time_zone(utc) if v[:time].is_a?(Date)
198
+ end
199
+ end
194
200
  Rollup.unscoped.upsert_all(records, **options)
195
201
  end
196
202
  end
data/lib/rollup/utils.rb CHANGED
@@ -33,7 +33,7 @@ class Rollup
33
33
  end
34
34
 
35
35
  def adapter_name
36
- Rollup.connection.adapter_name
36
+ Rollup.connection_db_config.adapter.to_s
37
37
  end
38
38
 
39
39
  def postgresql?
@@ -1,5 +1,5 @@
1
1
  class Rollup
2
2
  # not used in gemspec to avoid superclass mismatch
3
3
  # be sure to update there as well
4
- VERSION = "0.3.2"
4
+ VERSION = "0.4.1"
5
5
  end
data/lib/rollup.rb CHANGED
@@ -23,7 +23,7 @@ class Rollup < ActiveRecord::Base
23
23
 
24
24
  # use select_all due to incorrect casting with pluck
25
25
  sql = relation.order(:time).select(Utils.time_sql(interval), :value).to_sql
26
- result = connection.select_all(sql).rows
26
+ result = connection_pool.with_connection { |c| c.select_all(sql) }.rows
27
27
 
28
28
  Utils.make_series(result, interval)
29
29
  end
@@ -35,7 +35,7 @@ class Rollup < ActiveRecord::Base
35
35
 
36
36
  # use select_all to reduce allocations
37
37
  sql = relation.order(:time).select(Utils.time_sql(interval), :value, :dimensions).to_sql
38
- result = connection.select_all(sql).rows
38
+ result = connection_pool.with_connection { |c| c.select_all(sql) }.rows
39
39
 
40
40
  result.group_by { |r| JSON.parse(r[2]) }.map do |dimensions, rollups|
41
41
  {dimensions: dimensions, data: Utils.make_series(rollups, interval)}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rollups
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-10 00:00:00.000000000 Z
11
+ date: 2024-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '6.1'
19
+ version: '7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '6.1'
26
+ version: '7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: groupdate
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -68,14 +68,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
68
  requirements:
69
69
  - - ">="
70
70
  - !ruby/object:Gem::Version
71
- version: '3'
71
+ version: '3.1'
72
72
  required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - ">="
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  requirements: []
78
- rubygems_version: 3.5.3
78
+ rubygems_version: 3.5.16
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: Rollup time-series data in Rails