Class: Card::Reference
- Inherits:
-
Cardio::Record
- Object
- ActiveRecord::Base
- Cardio::Record
- Card::Reference
- Defined in:
- card/lib/card/reference.rb,
card/lib/card/reference/all.rb,
mod/tinymce_editor/lib/card/reference/nest_parser.rb
Overview
a Reference is a directional relationship from one card (the referer) to another (the referee).
Direct Known Subclasses
Defined Under Namespace
Modules: All Classes: NestParser
Class Method Summary collapse
-
.clean ⇒ Object
remove reference to and from missing cards.
-
.insert_in_slices(array) ⇒ Object
bulk insert improves performance considerably.
-
.map_referees(referee_key, referee_id) ⇒ Object
map existing reference to name to card via id.
-
.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
36 37 38 39 40 41 42 43 |
# File 'card/lib/card/reference.rb', line 36 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 |
.insert_in_slices(array) ⇒ Object
bulk insert improves performance considerably
19 20 21 22 23 |
# File 'card/lib/card/reference.rb', line 19 def insert_in_slices array array.each_slice(5000) do |slice| insert_all slice end end |
.map_referees(referee_key, referee_id) ⇒ Object
map existing reference to name to card via id
26 27 28 |
# File 'card/lib/card/reference.rb', line 26 def map_referees referee_key, referee_id where(referee_key: referee_key).update_all referee_id: referee_id 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
54 55 56 57 |
# File 'card/lib/card/reference.rb', line 54 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
47 48 49 50 |
# File 'card/lib/card/reference.rb', line 47 def repair_all clean each_card(&:update_references_out) end |
.unmap_referees(referee_id) ⇒ Object
references no longer refer to card, so remove id
31 32 33 |
# File 'card/lib/card/reference.rb', line 31 def unmap_referees referee_id where(referee_id: referee_id).update_all referee_id: nil end |