Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: ruby
rvm:
- 2.2.1
- 2.2.10
- 2.5.5
- 2.6.3
matrix:
Expand Down
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ gemspec
gem 'jruby-openssl', :platform => :jruby

group :test do
gem 'activerecord', '~> 4.2.0'
gem 'activerecord', '~> 5.2.0'
gem 'activerecord-jdbcsqlite3-adapter', :platform => [:jruby]
gem 'libxml-ruby', :platform => [:ruby, :mswin]
gem 'rake'
gem 'yard'
gem 'redcarpet', :platform => :ruby # For fast, Github-like Markdown
gem 'kramdown', :platform => :jruby # For Markdown without a C compiler
gem 'test-unit'
# This version of sqlite3 required for activerecord 4.2, not more recent.
# When bumping AR, may have to/want to adjust this to more recent versions.
gem 'sqlite3', "~> 1.3.0", :platform => [:ruby, :mswin]

# This version of sqlite3 oughta be good for activerecord 5.1+ hopefully
gem 'sqlite3', ">= 1.4.0", "< 2.0", :platform => [:ruby, :mswin]
end
19 changes: 9 additions & 10 deletions lib/oai/provider/model/activerecord_caching_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,16 @@ def next_set(token_string)
# select a subset of the result set, and return it with a
# resumption token to get the next subset
def select_partial(token)
if 0 == token.last
oaitoken = OaiToken.find_or_create_by(token: token.to_s)
if oaitoken.new_record_before_save?
OaiToken.connection.execute("insert into " +
"#{OaiEntry.table_name} (oai_token_id, record_id) " +
"select #{oaitoken.id}, id from #{model.table_name} where " +
"#{OaiToken.sanitize_sql(token_conditions(token))}")
end
oaitoken = OaiToken.find_by(token: token.to_s)

if 0 == token.last && oaitoken.nil?
oaitoken = OaiToken.create!(token: token.to_s)
OaiToken.connection.execute("insert into " +
"#{OaiEntry.table_name} (oai_token_id, record_id) " +
"select #{oaitoken.id}, id from #{model.table_name} where " +
"#{OaiToken.sanitize_sql(token_conditions(token))}")
end

oaitoken = OaiToken.find_by_token(token.to_s)
raise ResumptionTokenException.new unless oaitoken

PartialResult.new(
Expand All @@ -111,7 +110,7 @@ def select_partial(token)
end

def sweep_cache
OaiToken.destroy_all(["created_at < ?", Time.now - expire])
OaiToken.where(["created_at < ?", Time.now - expire]).destroy_all
end

def hydrate_records(records)
Expand Down
5 changes: 4 additions & 1 deletion test/activerecord_provider/config/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
ActiveRecord::Migration.verbose = false
ActiveRecord::Base.establish_connection :adapter => "sqlite3",
:database => ":memory:"
ActiveRecord::Migrator.up File.join(File.dirname(__FILE__), '..', 'database')

ActiveRecord::MigrationContext.new(File.join(File.dirname(__FILE__), '..', 'database')).migrate


2 changes: 1 addition & 1 deletion test/activerecord_provider/database/0001_oaipmh_tables.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class OaipmhTables < ActiveRecord::Migration
class OaipmhTables < ActiveRecord::Migration[4.2]
def self.up
create_table :oai_tokens do |t|
t.column :token, :string, :null => false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class ExclusiveSetDCField < ActiveRecord::Base

def self.sets
klass = Struct.new(:name, :spec)
self.uniq.pluck('`set`').compact.map do |spec|
self.distinct.pluck(:set).compact.map do |spec|
klass.new("Set #{spec}", spec)
end
end
Expand Down