lib/tobox/plugins/event_grouping.rb in tobox-0.6.1 vs lib/tobox/plugins/event_grouping.rb in tobox-0.7.0

- old
+ new

@@ -24,11 +24,17 @@ # get total from a group, to compare to the number of future locked rows. total_from_group = @ds.where(@group_column => group).count event_ids = @ds.where(@group_column => group) - .order(Sequel.desc(:run_at, nulls: :first), :id) - .for_update.skip_locked.select_map(:id) + + event_ids = if @configuration.visibility_type_bool? + event_ids.order(:id) + else + event_ids.order(Sequel.desc(@visibility_column, nulls: :first), :id) + end + + event_ids = event_ids.for_update.skip_locked.select_map(:id) if event_ids.size != total_from_group # this happens if concurrent workers locked different rows from the same group, # or when new rows from a given group have been inserted after the lock has been # acquired