Skip to content

Commit

Permalink
Merge pull request #373 from blackcandy-org/enhanced-sqlite
Browse files Browse the repository at this point in the history
Use enhanced sqlite adapter to avoid SQLITE_BUSY exception
  • Loading branch information
aidewoode authored May 6, 2024
2 parents 9fa1159 + 920d3c4 commit 890d726
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 32 deletions.
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ gem "puma", "~> 6.4.0"
# Default database
gem "sqlite3", "~> 1.7.0"

# Enhanced SQLite3 adapter
gem "activerecord-enhancedsqlite3-adapter", "~> 0.7.0"

# Cache store
gem "solid_cache", "~> 0.4.2"

# Background job processing
gem "solid_queue", "~> 0.2.1"

# Default stack for cache and pub/sub
# Default stack for pub/sub
gem "litestack", "~> 0.4.2"

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
Expand Down
6 changes: 5 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ GEM
activemodel (= 7.1.1)
activesupport (= 7.1.1)
timeout (>= 0.4.0)
activerecord-enhancedsqlite3-adapter (0.7.0)
activerecord (>= 7.1)
sqlite3 (>= 1.6)
activestorage (7.1.1)
actionpack (= 7.1.1)
activejob (= 7.1.1)
Expand Down Expand Up @@ -336,7 +339,7 @@ GEM
railties (>= 7)
solid_queue (0.2.1)
rails (~> 7.1)
sqlite3 (1.7.0)
sqlite3 (1.7.3)
mini_portile2 (~> 2.8.0)
sshkit (1.22.1)
base64
Expand Down Expand Up @@ -389,6 +392,7 @@ PLATFORMS
ruby

DEPENDENCIES
activerecord-enhancedsqlite3-adapter (~> 0.7.0)
acts_as_list (~> 1.1.0)
bcrypt (~> 3.1.11)
bootsnap (~> 1.17.0)
Expand Down
8 changes: 1 addition & 7 deletions app/models/concerns/imageable_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ module ImageableConcern
included do
has_one_attached :cover_image do |attachable|
attachable.variant :small, resize_to_fill: [200, 200]
attachable.variant :medium, resize_to_fill: [400, 400]
attachable.variant :medium, resize_to_fill: [400, 400], preprocessed: true
attachable.variant :large, resize_to_fill: [600, 600]
end

validate :content_type_of_cover_image

after_commit :transform_cover_image, if: :has_cover_image?
end

def has_cover_image?
Expand All @@ -28,8 +26,4 @@ def content_type_of_cover_image
errors.add(:cover_image, :invalid_content_type)
end
end

def transform_cover_image
cover_image.variant(:medium).processed
end
end
1 change: 0 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class Application < Rails::Application
config.exceptions_app = routes

config.active_storage.resolve_model_to_route = :rails_storage_proxy
config.active_storage.analyzers.delete ActiveStorage::Analyzer::ImageAnalyzer::Vips

config.solid_queue.silence_polling = true
config.solid_queue.preserve_finished_jobs = false
Expand Down
11 changes: 0 additions & 11 deletions test/models/album_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,4 @@ class AlbumTest < ActiveSupport::TestCase
test "should use default sort when use invalid sort value" do
assert_equal %w[album1 album2 album3 album4], Album.sort_records(:invalid).pluck(:name)
end

test "should transform cover image after attached" do
album = albums(:album1)
album.cover_image.attach(
io: StringIO.new(file_fixture("cover_image.jpg").read),
filename: "cover.jpg",
content_type: "image/jpeg"
)

assert album.cover_image.variant(:medium).send(:processed?)
end
end
11 changes: 0 additions & 11 deletions test/models/artist_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,4 @@ class ArtistTest < ActiveSupport::TestCase
test "should use default sort when use invalid sort value" do
assert_equal %w[artist1 artist2 various_artists], Artist.sort_records(:invalid).pluck(:name).compact
end

test "should transform cover image after attached" do
artist = artists(:artist1)
artist.cover_image.attach(
io: StringIO.new(file_fixture("cover_image.jpg").read),
filename: "cover.jpg",
content_type: "image/jpeg"
)

assert artist.cover_image.variant(:medium).send(:processed?)
end
end

0 comments on commit 890d726

Please sign in to comment.