Module: SpatialFeatures::FeatureImport

Extended by:
ActiveSupport::Concern
Includes:
QueuedSpatialProcessing
Defined in:
lib/spatial_features/has_spatial_features/feature_import.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from QueuedSpatialProcessing

#delay_update_features!, #failed_feature_update_jobs, #feature_update_error, #queue_update_spatial_cache, #running_feature_update_jobs, #spatial_processing_jobs, #spatial_processing_status, #updating_features?, #updating_features_failed?

Instance Method Details

#update_features!(skip_invalid: false, **options) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/spatial_features/has_spatial_features/feature_import.rb', line 22

def update_features!(skip_invalid: false, **options)
  options = options.reverse_merge(spatial_features_options)

  ActiveRecord::Base.transaction do
    imports = spatial_feature_imports(options[:import], options[:make_valid])
    cache_key = Digest::MD5.hexdigest(imports.collect(&:cache_key).join)

    return if features_cache_key_matches?(cache_key)

    run_callbacks :update_features do
      import_features(imports, skip_invalid)
      update_features_cache_key(cache_key)
      update_features_area

      if options[:spatial_cache].present? && options[:queue_spatial_cache]
        queue_update_spatial_cache(options.slice(:spatial_cache))
      else
        update_spatial_cache(options.slice(:spatial_cache))
      end
    end

    return true
  end
rescue StandardError => e
  if skip_invalid
    Rails.logger.warn "Error updating #{self.class} #{self.id}. #{e.message}"
    return nil
  else
    raise ImportError, e.message, e.backtrace
  end
end

#update_features_areaObject



60
61
62
63
64
# File 'lib/spatial_features/has_spatial_features/feature_import.rb', line 60

def update_features_area
  return unless has_attribute?(:features_area)
  self.features_area = features.area(:cache => false)
  update_column :features_area, features_area unless new_record?
end

#update_features_cache_key(cache_key) ⇒ Object



54
55
56
57
58
# File 'lib/spatial_features/has_spatial_features/feature_import.rb', line 54

def update_features_cache_key(cache_key)
  return unless has_spatial_features_hash?
  self.features_hash = cache_key
  update_column(:features_hash, features_hash) unless new_record?
end

#update_spatial_cache(options = {}) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/spatial_features/has_spatial_features/feature_import.rb', line 66

def update_spatial_cache(options = {})
  options = options.reverse_merge(spatial_features_options)

  Array.wrap(options[:spatial_cache]).select(&:present?).each do |klass|
    SpatialFeatures.cache_record_proximity(self, klass.to_s.constantize)
  end
end