Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Invalidating cache after insertion of a new element #60

Merged
merged 5 commits into from
May 1, 2024
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 Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ group :profiling do
gem "thin"
end

gem 'sparql-client', github: 'ontoportal-lirmm/sparql-client', branch: 'master'
gem 'sparql-client', github: 'ontoportal-lirmm/sparql-client', branch: 'development'
gem 'faraday', '2.7.11' #unpin if we no more support ruby 2.7
35 changes: 17 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
GIT
remote: https://github.com/ontoportal-lirmm/sparql-client.git
revision: 180c818f7715baac64b2699bb452ef5c756f62c5
branch: master
revision: c96da3ad479724a31ccd6217ab9939dddfaca40e
branch: development
specs:
sparql-client (1.0.1)
json_pure (>= 1.4)
net-http-persistent (= 2.9.4)
rdf (>= 1.0)
sparql-client (3.2.2)
net-http-persistent (~> 4.0, >= 4.0.2)
rdf (~> 3.2, >= 3.2.11)

PATH
remote: .
Expand Down Expand Up @@ -57,33 +56,33 @@ GEM
domain_name (~> 0.5)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
json_pure (2.7.1)
link_header (0.0.8)
macaddr (1.7.2)
systemu (~> 2.6.5)
method_source (1.0.0)
method_source (1.1.0)
mime-types (3.5.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2024.0206)
mime-types-data (3.2024.0305)
minitest (4.7.5)
multi_json (1.15.0)
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
net-http-persistent (2.9.4)
net-http-persistent (4.0.2)
connection_pool (~> 2.2)
netrc (0.11.0)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.0.4)
rack (2.2.8.1)
public_suffix (5.0.5)
rack (2.2.9)
rack-accept (0.4.5)
rack (>= 0.4)
rack-post-body-to-params (0.1.8)
activesupport (>= 2.3)
rack-protection (3.2.0)
base64 (>= 0.1.0)
rack (~> 2.2, >= 2.2.4)
rake (13.1.0)
rake (13.2.1)
rdf (3.2.11)
link_header (~> 0.0, >= 0.0.8)
rdf-raptor (3.2.0)
Expand All @@ -99,9 +98,9 @@ GEM
rdf-xsd (3.2.1)
rdf (~> 3.2)
rexml (~> 3.2)
redis (5.1.0)
redis-client (>= 0.17.0)
redis-client (0.20.0)
redis (5.2.0)
redis-client (>= 0.22.0)
redis-client (0.22.1)
connection_pool
request_store (1.6.0)
rack (>= 1.4)
Expand All @@ -111,7 +110,7 @@ GEM
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.2.6)
rsolr (2.5.0)
rsolr (2.6.0)
builder (>= 2.1.2)
faraday (>= 0.9, < 3, != 2.0.0)
ruby2_keywords (0.0.5)
Expand Down Expand Up @@ -163,4 +162,4 @@ DEPENDENCIES
uuid

BUNDLED WITH
2.2.33
2.4.22
40 changes: 21 additions & 19 deletions lib/goo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,26 @@ def self.add_sparql_backend(name, *opts)
opts = opts[0]
@@sparql_backends = @@sparql_backends.dup
@@sparql_backends[name] = opts
@@sparql_backends[name][:query]=Goo::SPARQL::Client.new(opts[:query],
{protocol: "1.1", "Content-Type" => "application/x-www-form-urlencoded",
read_timeout: 10000,
validate: false,
redis_cache: @@redis_client,
cube_options: @@cube_options})
@@sparql_backends[name][:update]=Goo::SPARQL::Client.new(opts[:update],
{protocol: "1.1", "Content-Type" => "application/x-www-form-urlencoded",
read_timeout: 10000,
validate: false,
redis_cache: @@redis_client,
cube_options: @@cube_options})
@@sparql_backends[name][:data]=Goo::SPARQL::Client.new(opts[:data],
{protocol: "1.1", "Content-Type" => "application/x-www-form-urlencoded",
read_timeout: 10000,
validate: false,
redis_cache: @@redis_client,
cube_options: @@cube_options})
@@sparql_backends[name][:query] = Goo::SPARQL::Client.new(opts[:query],
protocol: "1.1",
headers: { "Content-Type" => "application/x-www-form-urlencoded", "Accept" => "application/sparql-results+json"},
read_timeout: 10000,
validate: false,
redis_cache: @@redis_client)
@@sparql_backends[name][:update] = Goo::SPARQL::Client.new(opts[:update],
protocol: "1.1",
headers: { "Content-Type" => "application/x-www-form-urlencoded", "Accept" => "application/sparql-results+json"},
read_timeout: 10000,
validate: false,
redis_cache: @@redis_client,
cube_options: @@cube_options)
@@sparql_backends[name][:data] = Goo::SPARQL::Client.new(opts[:data],
protocol: "1.1",
headers: { "Content-Type" => "application/x-www-form-urlencoded", "Accept" => "application/sparql-results+json"},
read_timeout: 10000,
validate: false,
redis_cache: @@redis_client,
cube_options: @@cube_options)
@@sparql_backends[name][:backend_name] = opts[:backend_name]
@@sparql_backends.freeze
end
Expand Down Expand Up @@ -255,7 +257,7 @@ def self.configure
yield self
configure_sanity_check

init_search_connections
init_search_connections

@@namespaces.freeze
@@sparql_backends.freeze
Expand Down
3 changes: 1 addition & 2 deletions lib/goo/base/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,7 @@ def save(*opts)
batch_file.write(lines.join(""))
batch_file.flush()
else
data = graph_insert.to_a.reduce("") { |acc, x| acc << x.to_s + " " }
Goo.sparql_data_client.execute_append_request(graph, data, "application/x-turtle")
Goo.sparql_update_client.insert_data(graph_insert, graph: graph, use_insert_data: !Goo.backend_vo?)
end
rescue Exception => e
raise e
Expand Down
12 changes: 7 additions & 5 deletions lib/goo/config/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ def self.test_reset
if @@sparql_backends[:main][:query].url.to_s["localhost"].nil?
raise Exception, "only for testing"
end
@@sparql_backends[:main][:query] = Goo::SPARQL::Client.new("http://#{@settings.goo_host}:#{@settings.goo_port}#{@settings.goo_path_query}",
{protocol: "1.1", "Content-Type" => "application/x-www-form-urlencoded",
read_timeout: 300,
redis_cache: @@redis_client })
@@sparql_backends = {}
Goo.add_sparql_backend(:main,
backend_name: @settings.goo_backend_name,
query: "http://#{@settings.goo_host}:#{@settings.goo_port}#{@settings.goo_path_query}",
data: "http://#{@settings.goo_host}:#{@settings.goo_port}#{@settings.goo_path_data}",
update: "http://#{@settings.goo_host}:#{@settings.goo_port}#{@settings.goo_path_update}",
options: { rules: :NONE })
end


end
4 changes: 3 additions & 1 deletion lib/goo/sparql/query_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def build_query(ids, variables, graphs, patterns)
@query.filter(filter)
end

@query.union(*@unions) unless @unions.empty?
Array(@unions).each do |union|
@query.union(*union)
end

ids_filter(ids) if ids

Expand Down
15 changes: 14 additions & 1 deletion test/test_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ def self.after_suite
GooTestData.delete_test_case_data
end

def test_cache_invalidate
address = Address.all.first
Goo.use_cache = true
puts "save 1"
University.new(name: 'test', address: [address]).save
u2 = University.new(name: 'test', address: [address])
puts "request 1"
refute u2.valid?
expected_error = { :name => { :duplicate => "There is already a persistent resource with id `http://goo.org/default/university/test`" } }
assert_equal expected_error, u2.errors
Goo.use_cache = false
end

def test_cache_models
redis = Goo.redis_client
redis.flushdb
Expand All @@ -49,7 +62,7 @@ def test_cache_models
assert !key.nil?
assert redis.exists(key)


prg = programs.first
prg.bring_remaining
prg.credits = 999
Expand Down
Loading