activegraph-extensions 0.1.0 → 0.2.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: b28feac8e1598634606281d5dd8b70f019ac3038682abc635a5ef1d92c0e8b1e
4
- data.tar.gz: 1c021a54e63267817077da6942f9fa4f0c61437e112de2677f54db7f440f653e
3
+ metadata.gz: a2e80d374894f84875bb6c22ac207e14a15b617006b0ea83501ed24bda396b67
4
+ data.tar.gz: 39b1d0336158575caa6541aae2b134252d6ee13b4b1e096e24dea347be9e8568
5
5
  SHA512:
6
- metadata.gz: e6094af1c1c28ea6af47650e7b8399703e6c356addc72ac454b5c862c92fea563e284a5b80a96435cb41c9646a5f32f711cb0e314aea7a01c838d9476fe3d64b
7
- data.tar.gz: 7e56b8b83defdf3d9b21887dbecad56eb21927ff5c72a742b4f477bc2ad422aa24ebc135ff054a8398e18ebae6fe83642cb31f9cd526adbce3b2ddd38ab2bddc
6
+ metadata.gz: 25e8d8883488b355195d4bbbb38437b4d00a9c71913808c37862eabbc6e3a3cbeb58fc982f24515097dc264e6b29347377fd799aa022bf3b05980fbff0841df6
7
+ data.tar.gz: 6e8ca396f59cbb0b74b0e5bb53ab83d7ec7f67240788e39f82f7a2b15bdf5e4f54a3194a1553eda19f264d0b91a7f58bb32bd802c812a087fe90895ecf705958
@@ -41,10 +41,11 @@ module ActiveGraphExtensions
41
41
 
42
42
  def query_from_association_tree
43
43
  previous_with_vars = defalut_previous_with_vars
44
- with_associations_tree.paths.inject(query_as(identity).with(base_query_with_vars)) do |query, path|
45
- with_association_query_part(query, path, previous_with_vars).tap do
46
- previous_with_vars << var_fix(path_name(path), :collection)
47
- end
44
+
45
+ sorted_association_paths.inject(query_as(identity).with(base_query_with_vars)) do |query, path|
46
+ result = with_association_query_part(query, path, previous_with_vars)
47
+ previous_with_vars << var_fix(path_name(path), :collection)
48
+ path_name(path) == @early_pagination_path ? apply_early_order_skip_limit(result) : result
48
49
  end
49
50
  end
50
51
 
@@ -52,6 +53,40 @@ module ActiveGraphExtensions
52
53
  @with_vars&.dup || []
53
54
  end
54
55
 
56
+ def sorted_association_paths
57
+ return with_associations_tree.paths if skip_order?
58
+
59
+ priority, remaining = sort_paths
60
+ @early_pagination_path = find_early_pagination_path(priority)
61
+ priority + remaining
62
+ end
63
+
64
+ def sort_paths
65
+ ordered_names = path_names.select { |name| order_clause_for_query(name).present? }
66
+
67
+ with_associations_tree.paths.partition do |path|
68
+ name = path_name(path)
69
+ ordered_names.any? { |ordered_name| ordered_name == name || ordered_name.start_with?("#{name}.") }
70
+ end
71
+ end
72
+
73
+ def find_early_pagination_path(priority_paths)
74
+ return nil if skip_order? || priority_paths.blank?
75
+
76
+ path_name(priority_paths.last)
77
+ end
78
+
79
+ def apply_early_order_skip_limit(query)
80
+ @pagination_applied = true
81
+ query_from_chain(@postponed_chain, apply_order_from_spec(query), identity).break
82
+ end
83
+
84
+ def apply_order_from_spec(query)
85
+ query.order(
86
+ (@order_spec || []).flat_map { |key, order_specs| order_specs.map(&method(:order_clause).curry.call(key)) }
87
+ )
88
+ end
89
+
55
90
  def base_query_with_vars
56
91
  [ensure_distinct(identity)] + (@with_vars || [])
57
92
  end
@@ -93,11 +128,11 @@ module ActiveGraphExtensions
93
128
  end
94
129
 
95
130
  def before_pluck(query)
96
- return query if skip_order? && !include_with_path_length?
97
- base_query = query.order(
98
- (@order_spec || []).flat_map { |key, order_specs| order_specs.map(&method(:order_clause).curry.call(key)) }
99
- )
100
- query_from_chain(@postponed_chain, base_query, identity)
131
+ return query if (skip_order? || @pagination_applied) && !include_with_path_length?
132
+
133
+ base_query = apply_order_from_spec(query)
134
+ remaining_chain = @pagination_applied ? @postponed_chain.select { |link| link.clause == :order } : @postponed_chain
135
+ query_from_chain(remaining_chain, base_query, identity)
101
136
  end
102
137
 
103
138
  def node_aliase_for_collection(key, order_spec)
@@ -119,7 +154,7 @@ module ActiveGraphExtensions
119
154
  CLAUSES_TO_POSTPONE = %i[limit order skip].freeze
120
155
 
121
156
  def include_with_path_length?(path = @with_associations_tree)
122
- path.present? && (path.rel_length.present? || path.any? { |_, val| include_with_path_length?(val) })
157
+ !path.nil? && (path.rel_length.present? || path.any? { |_, val| include_with_path_length?(val) })
123
158
  end
124
159
 
125
160
  def chain
@@ -1,3 +1,3 @@
1
1
  module ActiveGraphExtensions
2
- VERSION = '0.1.0'
3
- end
2
+ VERSION = '0.2.0'
3
+ end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activegraph-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amit Suryavanshi
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 2025-01-13 00:00:00.000000000 Z
11
+ date: 2026-05-13 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: parslet
@@ -232,6 +233,7 @@ homepage: https://github.com/neo4jrb/activegraph-extensions/
232
233
  licenses:
233
234
  - MIT
234
235
  metadata: {}
236
+ post_install_message:
235
237
  rdoc_options:
236
238
  - "--quiet"
237
239
  - "--title"
@@ -253,7 +255,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
253
255
  - !ruby/object:Gem::Version
254
256
  version: '0'
255
257
  requirements: []
256
- rubygems_version: 3.6.2
258
+ rubygems_version: 3.5.16
259
+ signing_key:
257
260
  specification_version: 4
258
261
  summary: Additional features to activegraph
259
262
  test_files: []