Class: Upkeep::Subscriptions::PersistentReverseIndex
- Inherits:
-
Object
- Object
- Upkeep::Subscriptions::PersistentReverseIndex
- Defined in:
- lib/upkeep/subscriptions/persistent_reverse_index.rb
Constant Summary collapse
- LOOKUP_COLUMNS =
[ :subscription_id, :lookup_key_digest, :dependency_source, :lookup_table, :lookup_record_id_snapshot, :lookup_attribute, :dependency_table, :dependency_predicate_digest, :dependency_metadata_snapshot, :owner_ids_snapshot ].freeze
- SHAPE_LOOKUP_COLUMNS =
[ :subscription_shape_key, :lookup_key_digest, :dependency_source, :lookup_table, :lookup_record_id_snapshot, :lookup_attribute, :dependency_table, :dependency_predicate_digest, :dependency_metadata_snapshot, :owner_ids_snapshot ].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #entries_for(changes) ⇒ Object
-
#initialize(reverse_index:, index_record:, shape_index_record:, subscription_record:) ⇒ PersistentReverseIndex
constructor
A new instance of PersistentReverseIndex.
- #summary ⇒ Object
Constructor Details
#initialize(reverse_index:, index_record:, shape_index_record:, subscription_record:) ⇒ PersistentReverseIndex
Returns a new instance of PersistentReverseIndex.
38 39 40 41 42 43 |
# File 'lib/upkeep/subscriptions/persistent_reverse_index.rb', line 38 def initialize(reverse_index:, index_record:, shape_index_record:, subscription_record:) @reverse_index = reverse_index @index_record = index_record @shape_index_record = shape_index_record @subscription_record = subscription_record end |
Class Method Details
.canonical_lookup_value(value) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/upkeep/subscriptions/persistent_reverse_index.rb', line 74 def self.canonical_lookup_value(value) case value when Array value.map { |item| canonical_lookup_value(item) } when Hash value.keys.sort_by(&:to_s).map do |key| [canonical_lookup_value(key), canonical_lookup_value(value.fetch(key))] end when Symbol ["symbol", value.to_s] when String ["string", value.encode(Encoding::UTF_8)] else value end end |
.digest(value) ⇒ Object
70 71 72 |
# File 'lib/upkeep/subscriptions/persistent_reverse_index.rb', line 70 def self.digest(value) Digest::SHA256.hexdigest(JSON.generate(canonical_lookup_value(value))) end |
Instance Method Details
#entries_for(changes) ⇒ Object
45 46 47 |
# File 'lib/upkeep/subscriptions/persistent_reverse_index.rb', line 45 def entries_for(changes) persistent_entries_for(changes) end |
#summary ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/upkeep/subscriptions/persistent_reverse_index.rb', line 49 def summary direct_lookup_key_digests = index_record.distinct.pluck(:lookup_key_digest) shape_lookup_key_digests = shape_index_record.distinct.pluck(:lookup_key_digest) direct_entries = index_record.count shape_entries = shape_index_record.count { lookup_keys: (direct_lookup_key_digests + shape_lookup_key_digests).uniq.size, entries: direct_entries + shape_entries, direct: { lookup_keys: direct_lookup_key_digests.uniq.size, entries: direct_entries }, shape: { lookup_keys: shape_lookup_key_digests.uniq.size, entries: shape_entries, shape_keys: shape_index_record.distinct.count(:subscription_shape_key), subscriptions: subscription_record.where.not(subscription_shape_key: nil).count } } end |