lib/wcc/contentful/store/base.rb in wcc-contentful-1.2.1 vs lib/wcc/contentful/store/base.rb in wcc-contentful-1.3.0

- old
+ new

@@ -48,35 +48,35 @@ # Processes a data point received via the Sync API. This can be a published # entry or asset, or a 'DeletedEntry' or 'DeletedAsset'. The default # implementation calls into #set and #delete to perform the appropriate # operations in the store. def index(json) + # This implementation assumes that #delete and #set are individually thread-safe. + # No mutex is needed so long as the revisions are accurate. # Subclasses can override to do this in a more performant thread-safe way. # Example: postgres_store could do this in a stored procedure for speed - mutex.with_write_lock do - prev = - case type = json.dig('sys', 'type') - when 'DeletedEntry', 'DeletedAsset' - delete(json.dig('sys', 'id')) - else - set(json.dig('sys', 'id'), json) - end - - if (prev_rev = prev&.dig('sys', 'revision')) && - (next_rev = json.dig('sys', 'revision')) && - (next_rev < prev_rev) - # Uh oh! we overwrote an entry with a prior revision. Put the previous back. - return index(prev) - end - - case type + prev = + case type = json.dig('sys', 'type') when 'DeletedEntry', 'DeletedAsset' - nil + delete(json.dig('sys', 'id')) else - json + set(json.dig('sys', 'id'), json) end + + if (prev_rev = prev&.dig('sys', 'revision')) && + (next_rev = json.dig('sys', 'revision')) && + (next_rev < prev_rev) + # Uh oh! we overwrote an entry with a prior revision. Put the previous back. + return index(prev) end + + case type + when 'DeletedEntry', 'DeletedAsset' + nil + else + json + end end # Finds the first entry matching the given filter. A content type is required. # # @param [String] content_type The ID of the content type to search for. @@ -105,20 +105,12 @@ content_type: content_type, options: options ) end - def initialize - @mutex = Concurrent::ReentrantReadWriteLock.new - end - def ensure_hash(val) raise ArgumentError, 'Value must be a Hash' unless val.is_a?(Hash) end - - private - - attr_reader :mutex end end require_relative './query'