Skip to content

Instantly share code, notes, and snippets.

@Mattamorphic
Created April 15, 2021 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mattamorphic/796c99f05b6b2d4be625861dea7713d5 to your computer and use it in GitHub Desktop.
Save Mattamorphic/796c99f05b6b2d4be625861dea7713d5 to your computer and use it in GitHub Desktop.
Compression Rails
Tempfile.open(["#{Rails.root}/tmp/", ".csv"]) do |f|
# Write the batch to a csv file (cheaper than 5000 queries)
f = ActiveSupport::Gzip.compress(ModelDatum.where(model_id: 2).pluck(:id, :preprocessed_data).map(&:to_csv).join)
puts f.size()
puts ActiveSupport::Gzip.decompress(f)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment