paper_trail_diff 0.17.0 → 0.17.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 +4 -4
- data/CHANGELOG.md +15 -0
- data/lib/paper_trail_diff/change_attribution.rb +20 -5
- data/lib/paper_trail_diff/prepared_activity_index.rb +29 -5
- data/lib/paper_trail_diff/version.rb +1 -1
- data/lib/paper_trail_diff/version_association_candidate_scope.rb +26 -4
- data/sig/generated/paper_trail_diff/change_attribution.rbs +12 -3
- data/sig/generated/paper_trail_diff/prepared_activity_index.rbs +12 -1
- data/sig/generated/paper_trail_diff/version_association_candidate_scope.rbs +10 -2
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dde7a0e50f1010dc5381cb7bcca48e359d3ce85bacee4f2c2fd0c82f5edc9fca
|
|
4
|
+
data.tar.gz: f2c8da78755ef3f2a336fbe9f6fe66b72f87af31b99aad5bfdc6931b0dbeee9a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c687e380deaec613c0bb7b911d20f1041bd6f3ace09111d28cc060111a4865867d9bcbe57ae6dcc848dece9b64e1fd9bb5507f21a36611727ad651bfad8137d4
|
|
7
|
+
data.tar.gz: 5448861cc4a58b21b8560533f4237143f9cfb166ebaa1892e49be50ce354cc40c79cae206749250ed3912f5dd804b3c32a61129bac48937d446ab6ab6803c845
|
data/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,21 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file. The
|
|
4
4
|
project follows [Semantic Versioning](https://semver.org/).
|
|
5
5
|
|
|
6
|
+
## [0.17.1] - 2026-11-07
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
|
|
10
|
+
- A change to a root's own field that was saved without a version, after an
|
|
11
|
+
earlier version of the same transaction changed that field, is no longer
|
|
12
|
+
split with that earlier version's change. The earlier change is already in
|
|
13
|
+
the state a step starts from, so the step's row for the field is the
|
|
14
|
+
unversioned change alone.
|
|
15
|
+
- A window that starts inside a transaction now reports an associated
|
|
16
|
+
record that the transaction moved out of the root's tree before the
|
|
17
|
+
window's start, such as a comment moved to another parent and then saved
|
|
18
|
+
again or destroyed. The window before it leaves such a change to this
|
|
19
|
+
one, so a window split there no longer loses it from both halves.
|
|
20
|
+
|
|
6
21
|
## [0.17.0] - 2026-11-04
|
|
7
22
|
|
|
8
23
|
### Breaking changes
|
|
@@ -52,6 +52,12 @@ module PaperTrailDiff
|
|
|
52
52
|
#: () -> Integer
|
|
53
53
|
def length = @boundaries.length
|
|
54
54
|
|
|
55
|
+
# Whether the boundary is one of these, not merely one like it.
|
|
56
|
+
#: (ActivityBoundary) -> bool
|
|
57
|
+
def holds?(boundary)
|
|
58
|
+
@boundaries.any? { |held| held.equal?(boundary) }
|
|
59
|
+
end
|
|
60
|
+
|
|
55
61
|
# The record's boundaries among the first `count`, in order. The block
|
|
56
62
|
# names a boundary's record. The index is built whole before it is
|
|
57
63
|
# kept, so readers on two threads build the same one.
|
|
@@ -130,7 +136,7 @@ module PaperTrailDiff
|
|
|
130
136
|
touched = recorded_changes(versions, row.attribute)
|
|
131
137
|
return [credit(row, versions.last)] if touched.nil?
|
|
132
138
|
|
|
133
|
-
relevant = relevant(touched, row
|
|
139
|
+
relevant = relevant(touched, row)
|
|
134
140
|
return unrecorded(row, versions) if relevant.empty?
|
|
135
141
|
|
|
136
142
|
trusted = @complete || relevant.length < touched.length
|
|
@@ -139,14 +145,23 @@ module PaperTrailDiff
|
|
|
139
145
|
|
|
140
146
|
# The changes that make up the row's: from the last one that left the
|
|
141
147
|
# row's starting value; or else those after the last that reached it,
|
|
142
|
-
# which an earlier step reported; or else all of them
|
|
143
|
-
|
|
144
|
-
|
|
148
|
+
# which an earlier step reported; or else all of them, which for a root's
|
|
149
|
+
# own field are only the ones its sources saved. A step starts from the
|
|
150
|
+
# state before its source, and a root's fields are read at each of its
|
|
151
|
+
# versions, so the root versions its transaction saved before the sources
|
|
152
|
+
# are already in that state. A related record's fields are read as the
|
|
153
|
+
# transaction began, so those versions still count.
|
|
154
|
+
#: (Array[[ActivityBoundary, ValueChange]], ChangeRow) -> Array[[ActivityBoundary, ValueChange]]
|
|
155
|
+
def relevant(touched, row)
|
|
156
|
+
start = row.from
|
|
145
157
|
leaving = touched.rindex { |_version, change| change.from == start }
|
|
146
158
|
return touched.drop(leaving) if leaving
|
|
147
159
|
|
|
148
160
|
reaching = touched.rindex { |_version, change| change.to == start }
|
|
149
|
-
|
|
161
|
+
return touched.drop(reaching + 1) if reaching
|
|
162
|
+
return touched if row.record
|
|
163
|
+
|
|
164
|
+
touched.select { |version, _change| @sources.holds?(version) }
|
|
150
165
|
end
|
|
151
166
|
|
|
152
167
|
# A field none of the versions recorded changed without one, when they
|
|
@@ -217,15 +217,39 @@ module PaperTrailDiff
|
|
|
217
217
|
# survive a later pre-window reassignment just because that owner is absent.
|
|
218
218
|
# A range starting at a version starts before that version's transaction,
|
|
219
219
|
# as the scope's start does (see VersionBoundary.transaction_start), so a
|
|
220
|
-
# membership that ended earlier in that transaction still held there.
|
|
220
|
+
# membership that ended earlier in that transaction still held there. So
|
|
221
|
+
# did one that the record's own transaction across the start ended.
|
|
221
222
|
#: (untyped, untyped, untyped, String?, ActivityRange) -> bool
|
|
222
223
|
def eligible_version?(model, id, timestamp, event, range)
|
|
223
|
-
|
|
224
|
+
start = range.start_time
|
|
225
|
+
return true if timestamp >= start
|
|
224
226
|
return false if event == 'destroy'
|
|
225
227
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
!
|
|
228
|
+
versions = @records.versions_for_id(model, id)
|
|
229
|
+
first = versions.bsearch_index { |version| version.created_at > timestamp }
|
|
230
|
+
!first || replaced_after_start?(versions, first, range)
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
# Whether the record's next version, at `first`, replaced its state only
|
|
234
|
+
# from the range's start onward.
|
|
235
|
+
#: (Array[untyped], Integer, ActivityRange) -> bool
|
|
236
|
+
def replaced_after_start?(versions, first, range)
|
|
237
|
+
range.opening?(versions.fetch(first)) || crossed_start?(versions, first, range.start_time)
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
# Whether every version of a record from `first` up to the start is one
|
|
241
|
+
# of the transactions it saved a version in from the start onward.
|
|
242
|
+
#: (Array[untyped], Integer, untyped) -> bool
|
|
243
|
+
def crossed_start?(versions, first, start)
|
|
244
|
+
after = versions.bsearch_index { |version| version.created_at >= start }
|
|
245
|
+
return false unless after
|
|
246
|
+
|
|
247
|
+
versions.take(after).drop(first).all? do |version|
|
|
248
|
+
transaction_id = VersionBoundary.transaction_id(version)
|
|
249
|
+
transaction_id && versions.drop(after).any? do |other|
|
|
250
|
+
VersionBoundary.transaction_id(other) == transaction_id
|
|
251
|
+
end
|
|
252
|
+
end
|
|
229
253
|
end
|
|
230
254
|
|
|
231
255
|
# Each statement reads the rows of 500 transactions.
|
|
@@ -29,12 +29,21 @@ module PaperTrailDiff
|
|
|
29
29
|
Support.with_connection(@version_class) { |connection| condition_sql(connection) }
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
# A version saved before the start names the state there unless a later
|
|
33
|
+
# one saved before the start replaced it. PT-AT stores the keys a version
|
|
34
|
+
# saved, and a start inside a transaction reads each record as it stood
|
|
35
|
+
# before the transaction, so a later version that the record's
|
|
36
|
+
# transaction across the start saved before it replaced nothing yet.
|
|
37
|
+
# Without the version before it, a record that this transaction moved
|
|
38
|
+
# away is not found, nor is the transaction (see
|
|
39
|
+
# PreparedHistoryLoader#reload).
|
|
32
40
|
#: (untyped) -> String
|
|
33
41
|
def condition_sql(connection) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
34
42
|
outer = connection.quote_table_name(@version_class.table_name)
|
|
35
43
|
later = connection.quote_table_name('paper_trail_diff_later_versions')
|
|
44
|
+
crossing = connection.quote_table_name('paper_trail_diff_crossing_versions')
|
|
36
45
|
start_at = quote_time(connection, @start_at)
|
|
37
|
-
columns = quoted_columns(connection, outer, later)
|
|
46
|
+
columns = quoted_columns(connection, outer, later, crossing)
|
|
38
47
|
compact_sql(<<~SQL)
|
|
39
48
|
(
|
|
40
49
|
#{activity_condition(columns, start_at, connection)}
|
|
@@ -48,14 +57,22 @@ module PaperTrailDiff
|
|
|
48
57
|
AND #{columns.fetch(:later_item_id)} = #{columns.fetch(:outer_item_id)}
|
|
49
58
|
AND #{columns.fetch(:later_created_at)} < #{start_at}
|
|
50
59
|
AND #{columns.fetch(:later_created_at)} > #{columns.fetch(:outer_created_at)}
|
|
60
|
+
AND NOT EXISTS (
|
|
61
|
+
SELECT 1
|
|
62
|
+
FROM #{outer} #{crossing}
|
|
63
|
+
WHERE #{columns.fetch(:crossing_item_type)} = #{columns.fetch(:later_item_type)}
|
|
64
|
+
AND #{columns.fetch(:crossing_item_id)} = #{columns.fetch(:later_item_id)}
|
|
65
|
+
AND #{columns.fetch(:crossing_transaction_id)} = #{columns.fetch(:later_transaction_id)}
|
|
66
|
+
AND #{columns.fetch(:crossing_created_at)} >= #{start_at}
|
|
67
|
+
)
|
|
51
68
|
)
|
|
52
69
|
)
|
|
53
70
|
)
|
|
54
71
|
SQL
|
|
55
72
|
end
|
|
56
73
|
|
|
57
|
-
#: (untyped, String, String) -> Hash[Symbol, String]
|
|
58
|
-
def quoted_columns(connection, outer, later)
|
|
74
|
+
#: (untyped, String, String, String) -> Hash[Symbol, String]
|
|
75
|
+
def quoted_columns(connection, outer, later, crossing)
|
|
59
76
|
{
|
|
60
77
|
outer_created_at: column(connection, outer, 'created_at'),
|
|
61
78
|
outer_event: column(connection, outer, 'event'),
|
|
@@ -63,7 +80,12 @@ module PaperTrailDiff
|
|
|
63
80
|
outer_item_id: column(connection, outer, 'item_id'),
|
|
64
81
|
later_created_at: column(connection, later, 'created_at'),
|
|
65
82
|
later_item_type: column(connection, later, 'item_type'),
|
|
66
|
-
later_item_id: column(connection, later, 'item_id')
|
|
83
|
+
later_item_id: column(connection, later, 'item_id'),
|
|
84
|
+
later_transaction_id: column(connection, later, 'transaction_id'),
|
|
85
|
+
crossing_created_at: column(connection, crossing, 'created_at'),
|
|
86
|
+
crossing_item_type: column(connection, crossing, 'item_type'),
|
|
87
|
+
crossing_item_id: column(connection, crossing, 'item_id'),
|
|
88
|
+
crossing_transaction_id: column(connection, crossing, 'transaction_id')
|
|
67
89
|
}
|
|
68
90
|
end
|
|
69
91
|
|
|
@@ -46,6 +46,10 @@ module PaperTrailDiff
|
|
|
46
46
|
# : () -> Integer
|
|
47
47
|
def length: () -> Integer
|
|
48
48
|
|
|
49
|
+
# Whether the boundary is one of these, not merely one like it.
|
|
50
|
+
# : (ActivityBoundary) -> bool
|
|
51
|
+
def holds?: (ActivityBoundary) -> bool
|
|
52
|
+
|
|
49
53
|
# The record's boundaries among the first `count`, in order. The block
|
|
50
54
|
# names a boundary's record. The index is built whole before it is
|
|
51
55
|
# kept, so readers on two threads build the same one.
|
|
@@ -104,9 +108,14 @@ module PaperTrailDiff
|
|
|
104
108
|
|
|
105
109
|
# The changes that make up the row's: from the last one that left the
|
|
106
110
|
# row's starting value; or else those after the last that reached it,
|
|
107
|
-
# which an earlier step reported; or else all of them
|
|
108
|
-
#
|
|
109
|
-
|
|
111
|
+
# which an earlier step reported; or else all of them, which for a root's
|
|
112
|
+
# own field are only the ones its sources saved. A step starts from the
|
|
113
|
+
# state before its source, and a root's fields are read at each of its
|
|
114
|
+
# versions, so the root versions its transaction saved before the sources
|
|
115
|
+
# are already in that state. A related record's fields are read as the
|
|
116
|
+
# transaction began, so those versions still count.
|
|
117
|
+
# : (Array[[ActivityBoundary, ValueChange]], ChangeRow) -> Array[[ActivityBoundary, ValueChange]]
|
|
118
|
+
def relevant: (Array[[ ActivityBoundary, ValueChange ]], ChangeRow) -> Array[[ ActivityBoundary, ValueChange ]]
|
|
110
119
|
|
|
111
120
|
# A field none of the versions recorded changed without one, when they
|
|
112
121
|
# record every change of it they make.
|
|
@@ -123,10 +123,21 @@ module PaperTrailDiff
|
|
|
123
123
|
# survive a later pre-window reassignment just because that owner is absent.
|
|
124
124
|
# A range starting at a version starts before that version's transaction,
|
|
125
125
|
# as the scope's start does (see VersionBoundary.transaction_start), so a
|
|
126
|
-
# membership that ended earlier in that transaction still held there.
|
|
126
|
+
# membership that ended earlier in that transaction still held there. So
|
|
127
|
+
# did one that the record's own transaction across the start ended.
|
|
127
128
|
# : (untyped, untyped, untyped, String?, ActivityRange) -> bool
|
|
128
129
|
def eligible_version?: (untyped, untyped, untyped, String?, ActivityRange) -> bool
|
|
129
130
|
|
|
131
|
+
# Whether the record's next version, at `first`, replaced its state only
|
|
132
|
+
# from the range's start onward.
|
|
133
|
+
# : (Array[untyped], Integer, ActivityRange) -> bool
|
|
134
|
+
def replaced_after_start?: (Array[untyped], Integer, ActivityRange) -> bool
|
|
135
|
+
|
|
136
|
+
# Whether every version of a record from `first` up to the start is one
|
|
137
|
+
# of the transactions it saved a version in from the start onward.
|
|
138
|
+
# : (Array[untyped], Integer, untyped) -> bool
|
|
139
|
+
def crossed_start?: (Array[untyped], Integer, untyped) -> bool
|
|
140
|
+
|
|
130
141
|
# Each statement reads the rows of 500 transactions.
|
|
131
142
|
# : (untyped, untyped) -> Hash[String, Array[untyped]]
|
|
132
143
|
def load_habtm_rows: (untyped, untyped) -> Hash[String, Array[untyped]]
|
|
@@ -20,11 +20,19 @@ module PaperTrailDiff
|
|
|
20
20
|
# : () -> String
|
|
21
21
|
def candidate_condition: () -> String
|
|
22
22
|
|
|
23
|
+
# A version saved before the start names the state there unless a later
|
|
24
|
+
# one saved before the start replaced it. PT-AT stores the keys a version
|
|
25
|
+
# saved, and a start inside a transaction reads each record as it stood
|
|
26
|
+
# before the transaction, so a later version that the record's
|
|
27
|
+
# transaction across the start saved before it replaced nothing yet.
|
|
28
|
+
# Without the version before it, a record that this transaction moved
|
|
29
|
+
# away is not found, nor is the transaction (see
|
|
30
|
+
# PreparedHistoryLoader#reload).
|
|
23
31
|
# : (untyped) -> String
|
|
24
32
|
def condition_sql: (untyped) -> String
|
|
25
33
|
|
|
26
|
-
# : (untyped, String, String) -> Hash[Symbol, String]
|
|
27
|
-
def quoted_columns: (untyped, String, String) -> Hash[Symbol, String]
|
|
34
|
+
# : (untyped, String, String, String) -> Hash[Symbol, String]
|
|
35
|
+
def quoted_columns: (untyped, String, String, String) -> Hash[Symbol, String]
|
|
28
36
|
|
|
29
37
|
# : (Hash[Symbol, String], String, untyped) -> String
|
|
30
38
|
def activity_condition: (Hash[Symbol, String], String, untyped) -> String
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: paper_trail_diff
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.17.
|
|
4
|
+
version: 0.17.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alex Williams
|
|
@@ -314,11 +314,11 @@ licenses:
|
|
|
314
314
|
metadata:
|
|
315
315
|
allowed_push_host: https://rubygems.org
|
|
316
316
|
bug_tracker_uri: https://github.com/aheathwilliams/paper_trail_diff/issues
|
|
317
|
-
changelog_uri: https://github.com/aheathwilliams/paper_trail_diff/blob/v0.17.
|
|
318
|
-
documentation_uri: https://github.com/aheathwilliams/paper_trail_diff/blob/v0.17.
|
|
317
|
+
changelog_uri: https://github.com/aheathwilliams/paper_trail_diff/blob/v0.17.1/CHANGELOG.md
|
|
318
|
+
documentation_uri: https://github.com/aheathwilliams/paper_trail_diff/blob/v0.17.1/README.md
|
|
319
319
|
homepage_uri: https://github.com/aheathwilliams/paper_trail_diff
|
|
320
320
|
rubygems_mfa_required: 'true'
|
|
321
|
-
source_code_uri: https://github.com/aheathwilliams/paper_trail_diff/tree/v0.17.
|
|
321
|
+
source_code_uri: https://github.com/aheathwilliams/paper_trail_diff/tree/v0.17.1
|
|
322
322
|
rdoc_options: []
|
|
323
323
|
require_paths:
|
|
324
324
|
- lib
|