<commit_before>
module Factory

  def self.redis
    Sandstorm.redis
  end

  def self.contact(attrs = {})
    redis.multi
    redis.hmset("contact:#{attrs[:id]}:attrs", {'first_name' => attrs[:first_name],
      'last_name' => attrs[:last_name], 'email' => attrs[:email]}.flatten)
    redis.sadd('contact::attrs:ids', attrs[:id])
    redis.exec
  end

  def self.medium(contact, attrs = {})
    redis.multi
    redis.hmset("medium:#{attrs[:id]}:attrs", {'type' => attrs[:type],
      'address' => attrs[:address], 'interval' => attrs[:interval],
      'rollup_threshold' => attrs[:rollup_threshold]}.flatten)
    redis.sadd('medium::attrs:ids', attrs[:id].to_s)
    redis.sadd("medium::indices:by_type:#{attrs[:type]}", attrs[:type])

    redis.sadd("contact:#{contact.id}:assocs:medium_ids", attrs[:id].to_s)
    redis.exec
  end

  def self.tag(attrs = {})
    redis.multi
    redis.hmset("tag:#{attrs[:id]}:attrs", {'name' => attrs[:name]}.flatten)
    redis.sadd('tag::attrs:ids', attrs[:id])
    redis.hset("tag::indices:by_name", attrs[:name], attrs[:id])
    redis.exec
  end

  def self.check(attrs = {})
    attrs[:state] ||= 'ok'
    redis.multi
    redis.hmset("check:#{attrs[:id]}:attrs", {'name' => attrs[:name],
      'state' => attrs[:state], 'enabled' => (!!attrs[:enabled]).to_s}.flatten)
    redis.sadd('check::attrs:ids', attrs[:id])
    redis.hset("check::indices:by_name", attrs[:name], attrs[:id])
    redis.sadd("check::indices:by_state:#{attrs[:state]}", attrs[:id])
    redis.sadd("check::indices:by_enabled:#{!!attrs[:enabled]}", attrs[:id])

    redis.exec
  end

end<commit_msg>fixes for sandstorm index changes<commit_after>
module Factory

  def self.redis
    Sandstorm.redis
  end

  def self.contact(attrs = {})
    redis.multi
    redis.hmset("contact:#{attrs[:id]}:attrs", {'first_name' => attrs[:first_name],
      'last_name' => attrs[:last_name], 'email' => attrs[:email]}.flatten)
    redis.sadd('contact::attrs:ids', attrs[:id])
    redis.exec
  end

  def self.medium(contact, attrs = {})
    redis.multi
    redis.hmset("medium:#{attrs[:id]}:attrs", {'type' => attrs[:type],
      'address' => attrs[:address], 'interval' => attrs[:interval],
      'rollup_threshold' => attrs[:rollup_threshold]}.flatten)
    redis.sadd('medium::attrs:ids', attrs[:id].to_s)
    # type is known not to contain unsafe chars
    redis.sadd("medium::indices:by_type:string:#{attrs[:type]}", attrs[:type])

    redis.sadd("contact:#{contact.id}:assocs:medium_ids", attrs[:id].to_s)
    redis.exec
  end

  def self.tag(attrs = {})
    redis.multi
    redis.hmset("tag:#{attrs[:id]}:attrs", {'name' => attrs[:name]}.flatten)
    redis.sadd('tag::attrs:ids', attrs[:id])
    name = attrs[:name].gsub(/%/, '%%').gsub(/ /, '%20').gsub(/:/, '%3A')
    redis.hset("tag::indices:by_name", "string:#{name}", attrs[:id])
    redis.exec
  end

  def self.check(attrs = {})
    attrs[:state] ||= 'ok'
    redis.multi
    redis.hmset("check:#{attrs[:id]}:attrs", {'name' => attrs[:name],
      'state' => attrs[:state], 'enabled' => (!!attrs[:enabled]).to_s}.flatten)
    redis.sadd('check::attrs:ids', attrs[:id])
    name = attrs[:name].gsub(/%/, '%%').gsub(/ /, '%20').gsub(/:/, '%3A')
    redis.hset("check::indices:by_name", "string:#{name}", attrs[:id])
    # state is known not to contain unsafe chars
    redis.sadd("check::indices:by_state:string:#{attrs[:state]}", attrs[:id])
    redis.sadd("check::indices:by_enabled:boolean:#{!!attrs[:enabled]}", attrs[:id])

    redis.exec
  end

end
{'fraction_non_alphanumeric': 0.22770019948703335, 'fraction_numerical': 0.0017098888572242804, 'mean_word_length': 4.52755905511811, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '1650539', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1328, 'n_words': 187}