From 6bf4489efb2302697223a86ce3032bf9c20d8137 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Wed, 2 Oct 2024 18:08:04 -0700 Subject: [PATCH] jruby fixes Signed-off-by: Samuel Giddins --- gemstash.gemspec | 4 ++-- lib/gemstash/compact_index_builder.rb | 26 ++++++++------------------ lib/gemstash/env.rb | 3 ++- spec/integration_spec.rb | 2 +- 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/gemstash.gemspec b/gemstash.gemspec index 5522f6ea..ce232a01 100644 --- a/gemstash.gemspec +++ b/gemstash.gemspec @@ -39,7 +39,7 @@ you push your own private gems as well." spec.add_runtime_dependency "lru_redux", "~> 1.1" spec.add_runtime_dependency "psych", ">= 3.2.1" spec.add_runtime_dependency "puma", "~> 6.1" - spec.add_runtime_dependency "sequel", "~> 5.0" + spec.add_runtime_dependency "sequel", "~> 5.85" spec.add_runtime_dependency "server_health_check-rack", "~> 0.1" spec.add_runtime_dependency "sinatra", ">= 1.4", "< 5.0" spec.add_runtime_dependency "terminal-table", "~> 3.0" @@ -53,7 +53,7 @@ you push your own private gems as well." # spec.add_runtime_dependency "mysql2", "~> 0.4" if RUBY_PLATFORM == "java" - spec.add_runtime_dependency "jdbc-sqlite3", "~> 3.8" + spec.add_runtime_dependency "jdbc-sqlite3", "~> 3.46" else # SQLite 3.44+ is required for string_agg support spec.add_runtime_dependency "sqlite3", ">= 1.68", "< 3.0" diff --git a/lib/gemstash/compact_index_builder.rb b/lib/gemstash/compact_index_builder.rb index bec54407..a0b31b55 100644 --- a/lib/gemstash/compact_index_builder.rb +++ b/lib/gemstash/compact_index_builder.rb @@ -87,7 +87,7 @@ def build_result(force_rebuild: false) else ts = Time.now.iso8601 versions_file.create( - compact_index_public_versions(ts), ts + compact_index_public_versions(ts), ts.to_s.sub(/\+00:00\z/, "Z") ) @result = file.read resource.save("versions.list" => @result) @@ -176,14 +176,11 @@ def fetch_resource def build_result @result = CompactIndex.info(requirements_and_dependencies) - rescue Sequel::DatabaseError => e - raise "Error building info for #{@name}\n\n```sql\n#{e.sql}\n```\n" end private def requirements_and_dependencies - db_type = DB::Rubygem.db.database_type DB::Rubygem.association_left_join(versions: :dependencies). where(name: @name). where { versions[:indexed] }. @@ -192,24 +189,17 @@ def requirements_and_dependencies [versions[:number], versions[:platform], versions[:sha256], versions[:info_checksum], versions[:required_ruby_version], versions[:required_rubygems_version], versions[:created_at]] end. # rubocop:disable Style/MultilineBlockChain select_more do - sa = case db_type - when :sqlite then ->(a, b) { string_agg(a, b) } - else ->(a, b) { Sequel.string_agg(a, b) } - end - [sa.call(dependencies[:requirements], "@").order(dependencies[:rubygem_name], dependencies[:id]).as(:dep_req_agg), - sa.call(dependencies[:rubygem_name], ",").order(dependencies[:rubygem_name]).as(:dep_name_agg)] + [coalesce(Sequel.string_agg(dependencies[:requirements], "@").order(dependencies[:rubygem_name], dependencies[:id]), "").as(:dep_req_agg), + coalesce(Sequel.string_agg(dependencies[:rubygem_name], ",").order(dependencies[:rubygem_name]), "").as(:dep_name_agg)] end. # rubocop:disable Style/MultilineBlockChain map do |row| - reqs = row[:dep_req_agg]&.split("@") - dep_names = row[:dep_name_agg]&.split(",") + reqs = row[:dep_req_agg].split("@") + dep_names = row[:dep_name_agg].split(",") - raise "Dependencies and requirements are not the same size:\n reqs: #{reqs.inspect}\n dep_names: #{dep_names.inspect}\n row: #{row.inspect}" if dep_names&.size != reqs&.size + raise "Dependencies and requirements are not the same size:\n reqs: #{reqs.inspect}\n dep_names: #{dep_names.inspect}\n row: #{row.inspect}" if dep_names.size != reqs.size - deps = [] - if reqs - dep_names.zip(reqs).each do |name, req| - deps << CompactIndex::Dependency.new(name, req) - end + deps = dep_names.zip(reqs).map! do |name, req| + CompactIndex::Dependency.new(name, req) end CompactIndex::GemVersion.new( diff --git a/lib/gemstash/env.rb b/lib/gemstash/env.rb index ff2dc2fc..ef12f5b0 100644 --- a/lib/gemstash/env.rb +++ b/lib/gemstash/env.rb @@ -130,7 +130,8 @@ def db Sequel.connect("jdbc:sqlite:#{db_path}", config.database_connection_config) else Sequel.connect("sqlite://#{CGI.escape(db_path)}", config.database_connection_config) - end.tap {|db| raise "SQLite 3.44+ required, have #{db.sqlite_version}" unless db.sqlite_version >= 34_400 } + end + raise "SQLite 3.44+ required, have #{db.sqlite_version}" unless db.sqlite_version >= 34_400 when "postgres", "mysql", "mysql2" db_url = config[:db_url] raise "Missing DB URL" unless db_url diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 59875ba5..5cf5ebc0 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -127,7 +127,7 @@ it "is a conformant gem server", db_transaction: false do @gemstash.env.cache.flush expect( - execute("gem_server_conformance", ["--fail-fast", "--format", "progress", "--tag=~content_length_header"], + execute("gem_server_conformance", ["--format", "progress", "--tag=~content_length_header"], env: { "UPSTREAM" => host, "GEM_HOST_API_KEY" => auth_key }) ). to exit_success