From c4dd04d90244edf9e3f8e651d68eb128d5944bf2 Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Thu, 19 Oct 2023 19:09:16 +0200 Subject: [PATCH 1/2] include the in the select variables filtered variables --- lib/goo/sparql/query_builder.rb | 2 +- test/test_where.rb | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/goo/sparql/query_builder.rb b/lib/goo/sparql/query_builder.rb index 6077bd60..3b0f3589 100644 --- a/lib/goo/sparql/query_builder.rb +++ b/lib/goo/sparql/query_builder.rb @@ -407,7 +407,7 @@ def filter_query_strings(collection, graphs, klass, patterns.concat(filter_patterns) end end - #filter_variables << inspected_patterns.values.last + filter_variables << inspected_patterns.values.last end [query_filter_str, patterns, optional_patterns, filter_variables] end diff --git a/test/test_where.rb b/test/test_where.rb index 748dca88..c80fed33 100644 --- a/test/test_where.rb +++ b/test/test_where.rb @@ -263,11 +263,13 @@ def test_embed_two_levels end def test_paging_with_filter_order - total_count = Student.where.count - page_1 = Student.where.page(1, total_count - 1).order_by(name: :asc).to_a + + f = Goo::Filter.new(:birth_date) > DateTime.parse('1978-01-03') + total_count = Student.where.filter(f).count + page_1 = Student.where.include(:name, :birth_date).page(1, total_count - 1).filter(f).order_by(name: :asc).to_a refute_empty page_1 assert page_1.next? - page_2 = Student.where.page(page_1.next_page, total_count - 1).order_by(name: :asc).to_a + page_2 = Student.where.include(:name, :birth_date).page(page_1.next_page, total_count - 1).filter(f).order_by(name: :asc).to_a refute_empty page_2 From 5247e8d55ebf3e2b6ccb8dc68a9b9df080e44924 Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Thu, 19 Oct 2023 19:10:23 +0200 Subject: [PATCH 2/2] optimize pagination query by not re-doing the filters and order in the include query --- lib/goo/base/where.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/goo/base/where.rb b/lib/goo/base/where.rb index 5bc0fa8c..81cd26ce 100644 --- a/lib/goo/base/where.rb +++ b/lib/goo/base/where.rb @@ -209,6 +209,11 @@ def process_query_intl(count=false) options_load[:ids] = ids if ids models_by_id = {} + if @page_i && (options_load[:models].length > 0) + options_load.delete(:filters) + options_load.delete(:order_by) + end + if (@page_i && options_load[:models].length > 0) || (!@page_i && (@count.nil? || @count > 0)) models_by_id = Goo::SPARQL::Queries.model_load(options_load)