|
1 | 1 | class Card < ApplicationRecord |
2 | | - include Accessible, Assignable, Attachments, Broadcastable, Closeable, Colored, Entropic, Eventable, |
3 | | - Exportable, Golden, Mentions, Multistep, Pinnable, Postponable, Promptable, |
| 2 | + include Accessible, Assignable, Attachments, Broadcastable, Closeable, Colored, Commentable, |
| 3 | + Entropic, Eventable, Exportable, Golden, Mentions, Multistep, Pinnable, Postponable, Promptable, |
4 | 4 | Readable, Searchable, Stallable, Statuses, Storage::Tracked, Taggable, Triageable, Watchable |
5 | 5 |
|
6 | 6 | belongs_to :account, default: -> { board.account } |
7 | 7 | belongs_to :board |
8 | 8 | belongs_to :creator, class_name: "User", default: -> { Current.user } |
9 | 9 |
|
10 | | - has_many :comments, dependent: :destroy |
11 | 10 | has_one_attached :image, dependent: :purge_later |
12 | 11 |
|
13 | 12 | has_rich_text :description |
@@ -66,55 +65,6 @@ def filled? |
66 | 65 | end |
67 | 66 |
|
68 | 67 | private |
69 | | - STORAGE_BATCH_SIZE = 1000 |
70 | | - |
71 | | - # Override to include comments, but only load comments that have attachments. |
72 | | - # Cards can have thousands of comments; most won't have attachments. |
73 | | - # Streams in batches to avoid loading all IDs into memory at once. |
74 | | - def storage_transfer_records |
75 | | - comment_ids_with_attachments = storage_comment_ids_with_attachments |
76 | | - |
77 | | - if comment_ids_with_attachments.any? |
78 | | - [ self, *comments.where(id: comment_ids_with_attachments).to_a ] |
79 | | - else |
80 | | - [ self ] |
81 | | - end |
82 | | - end |
83 | | - |
84 | | - def storage_comment_ids_with_attachments |
85 | | - direct = [] |
86 | | - rich_text_map = {} |
87 | | - |
88 | | - # Stream comment IDs in batches to avoid loading all into memory |
89 | | - comments.in_batches(of: STORAGE_BATCH_SIZE) do |batch| |
90 | | - batch_ids = batch.pluck(:id) |
91 | | - |
92 | | - direct.concat \ |
93 | | - ActiveStorage::Attachment |
94 | | - .where(record_type: "Comment", record_id: batch_ids) |
95 | | - .distinct |
96 | | - .pluck(:record_id) |
97 | | - |
98 | | - ActionText::RichText |
99 | | - .where(record_type: "Comment", record_id: batch_ids) |
100 | | - .pluck(:id, :record_id) |
101 | | - .each { |rt_id, comment_id| rich_text_map[rt_id] = comment_id } |
102 | | - end |
103 | | - |
104 | | - embed_comment_ids = if rich_text_map.any? |
105 | | - rich_text_map.keys.each_slice(STORAGE_BATCH_SIZE).flat_map do |batch_ids| |
106 | | - ActiveStorage::Attachment |
107 | | - .where(record_type: "ActionText::RichText", record_id: batch_ids) |
108 | | - .distinct |
109 | | - .pluck(:record_id) |
110 | | - end.filter_map { |rt_id| rich_text_map[rt_id] } |
111 | | - else |
112 | | - [] |
113 | | - end |
114 | | - |
115 | | - (direct + embed_comment_ids).uniq |
116 | | - end |
117 | | - |
118 | 68 | def set_default_title |
119 | 69 | self.title = "Untitled" if title.blank? |
120 | 70 | end |
|
0 commit comments