Class: Card::Reference
- Inherits:
-
Cardio::Record
- Object
- ActiveRecord::Base
- Cardio::Record
- Card::Reference
- Defined in:
- lib/card/reference.rb,
lib/card/reference/all.rb
Overview
a Reference is a directional relationship from one card (the referer) to another (the referee).
Defined Under Namespace
Modules: All
Class Method Summary collapse
-
.clean ⇒ Object
remove reference to and from missing cards.
-
.map_referees(referee_key, referee_id) ⇒ Object
map existing reference to name to card via id.
-
.mass_insert(array) ⇒ Object
bulk insert improves performance considerably array takes form [ [referer_id, referee_id, referee_key, ref_type], …].
-
.recreate_all ⇒ Object
delete all references, then recreate them one by one faster than #repair_all, but not recommended for use on running sites.
-
.repair_all ⇒ Object
repair references one by one (delete, create, delete, create…) slower, but better than #recreate_all for use on running sites.
-
.unmap_referees(referee_id) ⇒ Object
references no longer refer to card, so remove id.
Instance Method Summary collapse
-
#referee ⇒ Object
card that is referred to.
-
#referer ⇒ Object
card that refers.
Class Method Details
.clean ⇒ Object
remove reference to and from missing cards
35 36 37 38 39 40 41 42 |
# File 'lib/card/reference.rb', line 35 def clean missing(:referee_id).where("referee_id IS NOT NULL").update_all referee_id: nil missing(:referer_id).pluck_in_batches(:id) do |group_ids| # used to be .delete_all here, but that was failing on large dbs Rails.logger.info "deleting batch of references" where("id in (#{group_ids.join ','})").delete_all end end |
.map_referees(referee_key, referee_id) ⇒ Object
map existing reference to name to card via id
25 26 27 |
# File 'lib/card/reference.rb', line 25 def map_referees referee_key, referee_id where(referee_key: referee_key).update_all referee_id: referee_id end |
.mass_insert(array) ⇒ Object
bulk insert improves performance considerably array takes form [ [referer_id, referee_id, referee_key, ref_type], …]
20 21 22 |
# File 'lib/card/reference.rb', line 20 def mass_insert array Card.connection.execute mass_insert_sql(array) if array.present? end |
.recreate_all ⇒ Object
delete all references, then recreate them one by one faster than #repair_all, but not recommended for use on running sites
53 54 55 56 |
# File 'lib/card/reference.rb', line 53 def recreate_all delete_all each_card(&:create_references_out) end |
.repair_all ⇒ Object
repair references one by one (delete, create, delete, create…) slower, but better than #recreate_all for use on running sites
46 47 48 49 |
# File 'lib/card/reference.rb', line 46 def repair_all clean each_card(&:update_references_out) end |
.unmap_referees(referee_id) ⇒ Object
references no longer refer to card, so remove id
30 31 32 |
# File 'lib/card/reference.rb', line 30 def unmap_referees referee_id where(referee_id: referee_id).update_all referee_id: nil end |