active_partition 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 942bdda1651b12d3dac2b0137a8d4ec024746bc6a494d7873d6328d1e5166ddc
4
- data.tar.gz: 1f5770064c39d828a6d7fb4b7d89e4d1f49711bfb8fb304c8ad73430032e29f2
3
+ metadata.gz: da2366e713d210800cf673216c0fef5f0789ca8defcc7400d4fcd45551441342
4
+ data.tar.gz: 1b6412d55ab7a691073fb4bc225db6991b1d46398f3cb7ed4a53bb489a49739b
5
5
  SHA512:
6
- metadata.gz: 18119f845f143524abedfe280c09cfdd4cca5591a56aa4428413ee19cf3bb9f035e951ad3d1c7100a12e80fefc81037dc82f613b50b549497a1586ec655192b2
7
- data.tar.gz: b56f0432c0c6fd7a42c8916547a97cd793be170e759f88b409ff9b2ec773f8a95c330997dfe111b4f37ac66137e52bd7ed3e105fdd547e8d5a92477ae3a78f2e
6
+ metadata.gz: c21a20dc712152a6b0279f842933bcc6629dda6bcb23b45d8a1cfcae11a1e4f2e1fe27a88e2767d0aee45baabe6a7a2c50783d3ba950ec67621b33e64d376a8c
7
+ data.tar.gz: 26dc7eb4a4867a0a9129bd68e3cd66b549548e4befdb0a17b51975f37b49c6ed3279fff631d7af3aa97842c2c6363420ad8cc9aad0fcd33f21df9c986148b4cc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_partition (0.5.0)
4
+ active_partition (0.4.0)
5
5
  rails
6
6
  range_operators (~> 0.1.1)
7
7
  rspec-rails
data/bin/console CHANGED
@@ -34,11 +34,11 @@ class OutgoingEventsWebhook < ActiveRecord::Base
34
34
  include ActivePartition::Partitionable
35
35
  self.primary_key = "id"
36
36
  self.partitioned_by = "created_at"
37
- self.partition_range = 1.hour
37
+ self.partition_range = 1.month
38
38
  self.partition_start_from = DateTime.new(2021, 1, 1)
39
39
 
40
40
  # You can choose 1 of the following 2 options
41
- self.retention_period = 1.day
41
+ self.retention_period = 1.month
42
42
  self.retention_partition_count = 3
43
43
  end
44
44
 
@@ -62,11 +62,18 @@ module ActivePartition::PartitionManagers
62
62
  def prepare_partition(partitioned_value, period)
63
63
  return if active_partitions_cover?(partitioned_value)
64
64
 
65
- diff = (partitioned_value.utc - latest_coverage_at) / period
66
- from_time = latest_coverage_at + (diff.floor * period)
67
- to_time = from_time + period
65
+ # when the latest_coverage_at is too far, the diff can be wrong (because leap years add up to the diff)
66
+ # therefore, we need to calculate the diff based on the period
67
+ # diff = (partitioned_value.utc - latest_coverage_at) / period
68
+ # from_time = latest_coverage_at + (diff.floor * period)
69
+ # to_time = from_time + period
70
+
71
+ from_time = latest_coverage_at
72
+ while !(from_time..(from_time + period)).cover?(partitioned_value) do
73
+ from_time += period * (partitioned_value > from_time ? 1 : -1)
74
+ end
68
75
 
69
- create_partition(from_time, to_time)
76
+ create_partition(from_time, from_time + period)
70
77
  end
71
78
 
72
79
  # Builds a partition name based on the given time range.
@@ -132,7 +139,7 @@ module ActivePartition::PartitionManagers
132
139
  def latest_partition_coverage_time
133
140
  partition_tables = @partition_adapter.get_all_supported_partition_tables
134
141
  reload_active_ranges(partition_tables)
135
- return (@partition_start_from || Time.current.beginning_of_hour.utc) if partition_tables.empty?
142
+ return (@partition_start_from || Time.current.beginning_of_hour).utc if partition_tables.empty?
136
143
 
137
144
  latest_partition_table = partition_tables.sort_by { |p_name| p_name.split("_").last.to_i }.last
138
145
  @latest_coverage_at = Time.at(latest_partition_table.split("_").last.to_i).utc
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActivePartition
4
- VERSION = "0.6.0"
4
+ VERSION = "0.7.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_partition
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thien Tran
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-31 00:00:00.000000000 Z
11
+ date: 2024-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug