<commit_before>=begin

Assets use a lot of classes to manage a particular uploaded file:

  Asset          -- main asset class.
  ImageAsset     -- a subclass of Asset using STI, for example.
  Asset::Version -- all the past and present versions of the main asset.
  Thumbnail      -- a processed representation of an Asset (usually a small image)

  Every asset has many versions. Each asset, and each version, also
  have many thumbnails.

  Additionally, three modules are included by Asset:
    AssetExtension::Upload      -- handles uploading data
    AssetExtension::Storage     -- handles where/how data is stored
    AssetExtension::Thumbnails  -- handles the creation of the thumbnails

  Asset::Versions have the latter two included as well.

  Additional modules used by assets:
    Media::MimeType -- where all the mime magicky stuff happens, including
                       determining which Asset subclass to create.
    Media::Process  -- processors for creating thumbnails.

TODO:

  * Image assets that are smaller than the thumbnails should not get thumbnails,
    or should only get one thumbnail if the format differs. It is a waste of space
    to keep four copies of the same image! (albeit, a very tiny image)

  create_table "asset_versions", :force => true do |t|
    t.integer  "asset_id",       :limit => 11
    t.integer  "version",        :limit => 11
    t.string   "content_type"
    t.string   "filename"
    t.integer  "size",           :limit => 11
    t.integer  "width",          :limit => 11
    t.integer  "height",         :limit => 11
    t.integer  "page_id",        :limit => 11
    t.integer  "user_id",        :limit => 11
    t.text     "comment"
    t.datetime "created_at"
    t.string   "versioned_type"
    t.datetime "updated_at"
  end

  add_index "asset_versions", ["asset_id"], :name => "index_asset_versions_asset_id"
  add_index "asset_versions", ["version"], :name => "index_asset_versions_version"
  add_index "asset_versions", ["page_id"], :name => "index_asset_versions_page_id"

  create_table "assets", :force => true do |t|
    t.string   "content_type"
    t.string   "filename"
    t.integer  "size",          :limit => 11
    t.integer  "width",         :limit => 11
    t.integer  "height",        :limit => 11
    t.integer  "page_id",       :limit => 11
    t.datetime "created_at"
    t.integer  "version",       :limit => 11
    t.string   "type"
    t.integer  "page_terms_id", :limit => 11
    t.boolean  "is_attachment",               :default => false
    t.boolean  "is_image"
    t.boolean  "is_audio"
    t.boolean  "is_video"
    t.boolean  "is_document"
    t.datetime "updated_at"
    t.string   "caption"
    t.datetime "taken_at"
    t.string   "credit"
    t.integer  "user_id",        :limit => 11
    t.text     "comment"
  end

  add_index "assets", ["version"], :name => "index_assets_version"
  add_index "assets", ["page_id"], :name => "index_assets_page_id"
  add_index "assets", ["page_terms_id"], :name => "pterms"

=end

class Asset < ActiveRecord::Base
  include Crabgrass::Page::Data

  # Polymorph does not seem to be working with subclasses of Asset. For parent_type,
  # it always picks "Asset". So, we hardcode what the query should be:
  POLYMORPH_AS_PARENT = lambda { "SELECT * FROM thumbnails WHERE parent_id = #{self.id} AND parent_type = \"#{self.type_as_parent}\"" }

  # fields in assets table not in asset_versions
  NON_VERSIONED = %w(page_terms_id is_attachment is_image is_audio is_video is_document caption taken_at credit)

  # This is included here because Asset may take new attachment file data, but
  # Asset::Version and Thumbnail don't need to.<commit_msg>finder_sql lambda needs an argument.<commit_after>=begin

Assets use a lot of classes to manage a particular uploaded file:

  Asset          -- main asset class.
  ImageAsset     -- a subclass of Asset using STI, for example.
  Asset::Version -- all the past and present versions of the main asset.
  Thumbnail      -- a processed representation of an Asset (usually a small image)

  Every asset has many versions. Each asset, and each version, also
  have many thumbnails.

  Additionally, three modules are included by Asset:
    AssetExtension::Upload      -- handles uploading data
    AssetExtension::Storage     -- handles where/how data is stored
    AssetExtension::Thumbnails  -- handles the creation of the thumbnails

  Asset::Versions have the latter two included as well.

  Additional modules used by assets:
    Media::MimeType -- where all the mime magicky stuff happens, including
                       determining which Asset subclass to create.
    Media::Process  -- processors for creating thumbnails.

TODO:

  * Image assets that are smaller than the thumbnails should not get thumbnails,
    or should only get one thumbnail if the format differs. It is a waste of space
    to keep four copies of the same image! (albeit, a very tiny image)

  create_table "asset_versions", :force => true do |t|
    t.integer  "asset_id",       :limit => 11
    t.integer  "version",        :limit => 11
    t.string   "content_type"
    t.string   "filename"
    t.integer  "size",           :limit => 11
    t.integer  "width",          :limit => 11
    t.integer  "height",         :limit => 11
    t.integer  "page_id",        :limit => 11
    t.integer  "user_id",        :limit => 11
    t.text     "comment"
    t.datetime "created_at"
    t.string   "versioned_type"
    t.datetime "updated_at"
  end

  add_index "asset_versions", ["asset_id"], :name => "index_asset_versions_asset_id"
  add_index "asset_versions", ["version"], :name => "index_asset_versions_version"
  add_index "asset_versions", ["page_id"], :name => "index_asset_versions_page_id"

  create_table "assets", :force => true do |t|
    t.string   "content_type"
    t.string   "filename"
    t.integer  "size",          :limit => 11
    t.integer  "width",         :limit => 11
    t.integer  "height",        :limit => 11
    t.integer  "page_id",       :limit => 11
    t.datetime "created_at"
    t.integer  "version",       :limit => 11
    t.string   "type"
    t.integer  "page_terms_id", :limit => 11
    t.boolean  "is_attachment",               :default => false
    t.boolean  "is_image"
    t.boolean  "is_audio"
    t.boolean  "is_video"
    t.boolean  "is_document"
    t.datetime "updated_at"
    t.string   "caption"
    t.datetime "taken_at"
    t.string   "credit"
    t.integer  "user_id",        :limit => 11
    t.text     "comment"
  end

  add_index "assets", ["version"], :name => "index_assets_version"
  add_index "assets", ["page_id"], :name => "index_assets_page_id"
  add_index "assets", ["page_terms_id"], :name => "pterms"

=end

class Asset < ActiveRecord::Base
  include Crabgrass::Page::Data

  # Polymorph does not seem to be working with subclasses of Asset. For parent_type,
  # it always picks "Asset". So, we hardcode what the query should be:
  POLYMORPH_AS_PARENT = lambda { |a| "SELECT * FROM thumbnails WHERE parent_id = #{self.id} AND parent_type = \"#{self.type_as_parent}\"" }

  # fields in assets table not in asset_versions
  NON_VERSIONED = %w(page_terms_id is_attachment is_image is_audio is_video is_document caption taken_at credit)

  # This is included here because Asset may take new attachment file data, but
  # Asset::Version and Thumbnail don't need to.
{'fraction_non_alphanumeric': 0.10017622339704486, 'fraction_numerical': 0.0075911617188559035, 'mean_word_length': 2.9182156133828996, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5281929', 'n_tokens_mistral': 2355, 'n_tokens_neox': 2206, 'n_words': 766}