active_partition 0.6.0 → 0.7.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 +4 -4
- data/Gemfile.lock +1 -1
- data/bin/console +2 -2
- data/lib/active_partition/partition_managers/time_range.rb +12 -5
- data/lib/active_partition/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da2366e713d210800cf673216c0fef5f0789ca8defcc7400d4fcd45551441342
|
4
|
+
data.tar.gz: 1b6412d55ab7a691073fb4bc225db6991b1d46398f3cb7ed4a53bb489a49739b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c21a20dc712152a6b0279f842933bcc6629dda6bcb23b45d8a1cfcae11a1e4f2e1fe27a88e2767d0aee45baabe6a7a2c50783d3ba950ec67621b33e64d376a8c
|
7
|
+
data.tar.gz: 26dc7eb4a4867a0a9129bd68e3cd66b549548e4befdb0a17b51975f37b49c6ed3279fff631d7af3aa97842c2c6363420ad8cc9aad0fcd33f21df9c986148b4cc
|
data/Gemfile.lock
CHANGED
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.
|
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.
|
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
|
66
|
-
|
67
|
-
|
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,
|
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
|
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
|
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.
|
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-
|
11
|
+
date: 2024-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|