Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Katkov committed Oct 10, 2023
1 parent 8e1bb5d commit 4c57357
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
16 changes: 8 additions & 8 deletions lib/generators/solid_cache/install/install_generator.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'rails/generators/active_record'
require "rails/generators/active_record"

class SolidCache::InstallGenerator < Rails::Generators::Base
include ActiveRecord::Generators::Migration

source_root File.expand_path("templates", __dir__)
class_option :skip_migrations, type: :boolean, default: nil, desc: "Skip migrations"
class_option :index, type: :string, default: 'btree', desc: "Index type for key column"
class_option :index, type: :string, default: "btree", desc: "Index type for key column"

def add_rails_cache
%w[development test production].each do |env_name|
Expand All @@ -17,12 +17,12 @@ def add_rails_cache

def create_migrations
return if options[:skip_migrations]

case options[:index]
when 'btree'
migration_template 'create_solid_cache_entries_btree.rb', 'db/migrate/create_solid_cache_entries.rb'
when 'hash'
migration_template 'create_solid_cache_entries_hash.rb', 'db/migrate/create_solid_cache_entries.rb'
when "btree"
migration_template "create_solid_cache_entries_btree.rb", "db/migrate/create_solid_cache_entries.rb"
when "hash"
migration_template "create_solid_cache_entries_hash.rb", "db/migrate/create_solid_cache_entries.rb"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ def change
t.binary :key, null: false, limit: 1024
t.binary :value, null: false, limit: 512.megabytes
t.datetime :created_at, null: false

t.index :key, unique: true
end
end
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ def change
t.binary :key, null: false, limit: 1024
t.binary :value, null: false, limit: 512.megabytes
t.datetime :created_at, null: false

t.index :key, unique: true, using: :hash
end
end
end

end
2 changes: 1 addition & 1 deletion lib/solid_cache/store/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def clear(options = nil)

private
def primary_key_using_hash_index?
ActiveRecord::Base.connection.indexes(:activesupport_cache_entries).first {|i| i.columns.first == 'key'}.using == :hash
ActiveRecord::Base.connection.indexes(:activesupport_cache_entries).first { |i| i.columns.first == "key" }.using == :hash
end

def read_entry(key, **options)
Expand Down
6 changes: 3 additions & 3 deletions lib/tasks/solid_cache_tasks.rake
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
desc "Copy over the migration, and set cache"
namespace :solid_cache do
task :install, [:index] do |_t, args|
args.with_defaults(index: 'btree')
task :install, [ :index ] do |_t, args|
args.with_defaults(index: "btree")

if args[:index] == 'btree' || args[:index] == 'hash'
if args[:index] == "btree" || args[:index] == "hash"
Rails::Command.invoke :generate, [ "solid_cache:install", "--index=#{args[:index]}" ]
else
abort "Invalid index type - only 'btree' and 'hash' are supported."
Expand Down

0 comments on commit 4c57357

Please sign in to comment.