@@ -129,9 +129,23 @@ class Place::Bookings::GrantAreaAccess < PlaceOS::Driver
129129 security
130130 end
131131
132+ @check_mutex : Mutex = Mutex .new
133+ @performing_check : Bool = false
134+ @check_queued : Bool = false
135+
132136 def ensure_booking_access
133137 errors = [] of String
134138
139+ @check_mutex .synchronize do
140+ if @performing_check
141+ @check_queued = true
142+ return
143+ end
144+
145+ @performing_check = true
146+ @check_queued = false
147+ end
148+
135149 @mutex .synchronize do
136150 now = Time .local(timezone).at_beginning_of_day
137151 end_of_day = 3 .days.from_now.in(timezone).at_end_of_day
@@ -158,13 +172,16 @@ class Place::Bookings::GrantAreaAccess < PlaceOS::Driver
158172
159173 # apply access this access to the system, need to find the differences
160174 allocations = @allocations
161- return if allocations == access_required
175+ logger.debug { " found #{ allocations.size } users that need access" }
176+
177+ if allocations == access_required
178+ logger.debug { " no access changes are required" }
179+ return
180+ end
162181
163182 remove = Hash (String , Array (String )).new { |hash , key | hash[key] = [] of String }
164183 add = Hash (String , Array (String )).new { |hash , key | hash[key] = [] of String }
165184
166- logger.debug { " found #{ allocations.size } users that need access changes" }
167-
168185 # Collect all keys from both hashes
169186 all_keys = allocations.keys.concat(access_required.keys)
170187 all_keys.each do |key |
@@ -242,6 +259,11 @@ class Place::Bookings::GrantAreaAccess < PlaceOS::Driver
242259
243260 # save the newly applied access permissions
244261 define_setting(:permissions_allocated , access_required)
262+ ensure
263+ @check_mutex .synchronize do
264+ @performing_check = false
265+ spawn { ensure_booking_access } if @check_queued
266+ end
245267 end
246268
247269 self [:sync_errors ] = errors
0 commit comments