Skip to content

Conversation

@jorgemanrubia
Copy link
Member

@jorgemanrubia jorgemanrubia commented Dec 5, 2025

This tracks storage at the account and board level.

Comments, cards, boards will notify up storage changes, offering an opportunity to store the change to the ancestors in the containment hierarchy.

We only count the storage taken by Action Text attachments for now.

Thanks for @packagethief for feedback on the approach, based on our experience with Basecamp 🙏

  • Move board update to job too
  • Run migration in production

@@ -0,0 +1,19 @@
module ActionTextContentBytesUsed
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extends ActionText objects to query for the used storage.

@jorgemanrubia jorgemanrubia force-pushed the adjust-storage-tracking branch from 262f62d to 70fc030 Compare December 5, 2025 14:37
@jorgemanrubia jorgemanrubia force-pushed the adjust-storage-tracking branch from 70fc030 to 6b4c02e Compare December 5, 2025 14:41
Copy link
Member

@flavorjones flavorjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@@ -0,0 +1,19 @@
module ActionTextContentStorageTracking
def bytes_used
attachables.sum { |attachable| attachable.try(:byte_size) || 0 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use attachable_filesize here which tries both byte_size and filesize:

Suggested change
attachables.sum { |attachable| attachable.try(:byte_size) || 0 }
attachables.sum { |attachable| attachable.attachable_filesize || 0 }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice TIL

@flavorjones
Copy link
Member

Should we display "storage used" somewhere on the Account Settings page?

@jorgemanrubia
Copy link
Member Author

Should we display "storage used" somewhere on the Account Settings page?

I was trying to get the internals here, but yeah that will be the next step once this gets merged (cc @jzimdars)

@jorgemanrubia jorgemanrubia force-pushed the adjust-storage-tracking branch from 2cbdd4f to 8f48b89 Compare December 5, 2025 15:43
@jorgemanrubia jorgemanrubia force-pushed the adjust-storage-tracking branch 4 times, most recently from adb2a27 to 9ac37fb Compare December 5, 2025 15:59
So that the system is more robust and it is faster to recalculate storage taken by account
@jorgemanrubia jorgemanrubia force-pushed the adjust-storage-tracking branch from 9ac37fb to 1e2e9e1 Compare December 5, 2025 16:01
Comment on lines +14 to +23
def count_bytes_used
total_bytes = 0

cards.with_rich_text_description_and_embeds.find_each do |card|
total_bytes += card.bytes_used
total_bytes += card.comments.with_rich_text_body_and_embeds.sum(&:bytes_used)
end

total_bytes
end
Copy link
Member

@packagethief packagethief Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I think we'd just iterate over the cards and ask them to recalculate themselves, taking care of their own dependents.

Each class that includes ::StorageTracking is responsible for providing recalculate_bytes_used and having it return the new value. They can implement their own caching policy as they see fit. Cards and comments, for example, don't cache the value, but having them do so would be easy to add.

# Account::StorageTracking
def recalculate_bytes_used
  boards.find_each(&:recalculate_bytes_used).sum.tap do |value|
    update_column :bytes_used, value
  end
end

# Board::StorageTracking
def recalculate_bytes_used
  cards.find_each(&:recalculate_bytes_used).sum.tap do |value|
    update_column :bytes_used, value
  end
end

# Card::StorageTracking (doesn't cache the result)
def recalculate_bytes_used
  bytes_used = rich_text_associations.sum { # ... }
  bytes_used + comments.find_each(&:recalculate_bytes_used).sum
end

If we need to in the future, we could implement a more efficient calculate_bytes_used. It would use cached values where possible without performing a full recalculation.

@jorgemanrubia
Copy link
Member Author

jorgemanrubia commented Dec 7, 2025

Closing for now since @jeremy has a better approach in mind to try here ✨✨

#2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants