metadata_presenter 3.0.2 → 3.0.3

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: de4803f047828b34c584bbe1a6e3634e55ab62fb7dc5cf84af0e74179fab2bfd
4
- data.tar.gz: 48d367b837b22dae94e57158a1f23471ac5c8f51bac70ece003bcaa528eed909
3
+ metadata.gz: bbf82d6e0d0d2d3456a197111c4f9819c7fb67c8d260fc7db6c9c8be24788d30
4
+ data.tar.gz: '052159fc7c7fe9b069586828b56a9b89abb7737a1714da371616faf484af2949'
5
5
  SHA512:
6
- metadata.gz: 45740afe9df6c30057f70e6c8c8cd24f913c90f6bb63c49a04c4104abbf65c3a87333f648cb8ff55be537ff754a5cb1e86745dd9762acb2df2201ba03bfeebda
7
- data.tar.gz: dd590ea13e20ce649630a7640e5877d56dca8081e2b8c118c22da9e4f43e62afaa39b3ddbdf185cc1e6b4f244aaafb9b37b1ca4d6995f8bd90a3deb5b95d8a60
6
+ metadata.gz: 194308706ef13433ad2bebba4bb8c3367e84f0b3d8de4874a67ea0c47065f4a47717c7a29c8564809a0a319d0d381b6122c0203abf0d4fb39d8e618e56ab9cfc
7
+ data.tar.gz: 815a4558475e02b8b32805f2c8d3c3fc7276b33d1b3497d81221332b3a3b46d1f29248d246267209cfe62692f38f00b0c3b937b37d973568cb59d25cbdb9c34d
@@ -124,12 +124,15 @@ module MetadataPresenter
124
124
  # Always traverse the route from the start_from uuid. Defaulting to the
125
125
  # start page of the form unless otherwise specified.
126
126
  # Get all the potential routes from any branching points that exist.
127
+ traversed_uuids = []
127
128
  route_from_start.traverse
128
129
  @routes.append(route_from_start)
129
- traversed_routes = route_from_start.routes
130
-
130
+ traversed_uuids.concat(route_from_start.flow_uuids)
131
+ routes_to_traverse = route_from_start.routes
131
132
  index = 0
132
- until traversed_routes.empty?
133
+ Rails.logger.info("Total potential routes: #{total_potential_routes}")
134
+
135
+ until routes_to_traverse.empty?
133
136
  if index > total_potential_routes
134
137
  ActiveSupport::Notifications.instrument(
135
138
  'exceeded_total_potential_routes',
@@ -138,17 +141,22 @@ module MetadataPresenter
138
141
  break
139
142
  end
140
143
 
141
- route = traversed_routes.shift
144
+ route = routes_to_traverse.shift
142
145
  @routes.append(route)
143
146
 
144
- # Every route exiting a branching point needs to be traversed and any
145
- # additional routes from other branching points collected and then also
146
- # traversed.
147
+ # Traverse the route and add any nested routes to the list of routes to
148
+ # traverse.
149
+ # If the first flow_uuid in the route has already been traversed, then
150
+ # this route is looping back, so we don't need to traverse the nested routes.
147
151
  route.traverse
148
- traversed_routes |= route.routes
152
+ unless traversed_uuids.include?(route.flow_uuids.first)
153
+ routes_to_traverse.concat(route.routes)
154
+ end
155
+ traversed_uuids.concat(route.flow_uuids)
149
156
 
150
157
  index += 1
151
158
  end
159
+ Rails.logger.info("Total routes traversed: #{index}")
152
160
  end
153
161
 
154
162
  def set_column_numbers
@@ -441,15 +449,12 @@ module MetadataPresenter
441
449
  branch.all_destination_uuids.reject { |uuid| @traversed.include?(uuid) }
442
450
  end
443
451
 
444
- # Deliberately not including the default next for each branch as when row
445
- # zero is created it takes the first available conditional for each branch.
446
- # The remaining are then used to create route objects. Therefore the total
447
- # number of remaining routes will be the same as the total of all the branch
448
- # conditionals.
449
- # Add 1 additional route as that represents the route_from_start.
452
+ # Calculate an upper limit to prevent infinite traversal
453
+ # Not easy to calculate exactly, aiming for a number that is bigger than
454
+ # total possible routes but not too much bigger.
450
455
  def total_potential_routes
451
- @total_potential_routes ||=
452
- service.branches.sum { |branch| branch.conditionals.size } + 1
456
+ total_conditionals = service.branches.sum { |branch| branch.conditionals.size + 1 }
457
+ @total_potential_routes ||= total_conditionals * total_conditionals
453
458
  end
454
459
  end
455
460
  end
@@ -1,3 +1,3 @@
1
1
  module MetadataPresenter
2
- VERSION = '3.0.2'.freeze
2
+ VERSION = '3.0.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metadata_presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - MoJ Forms
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-26 00:00:00.000000000 Z
11
+ date: 2023-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_design_system_formbuilder