Skip to content

Commit b0c2893

Browse files
pimpinclaude
andcommitted
feat: enable prepared statement plan caching via adhoc: false in relation queries
Read adhoc from N1ql.config in build_query_options so all Relation-based queries (.where, .all, .first, .last, .ids, update_all, delete_all, etc.) also benefit from server-side plan caching without any caller changes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 44a5dbf commit b0c2893

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/couchbase-orm/relation.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ def build_update_with_params(params, **cond)
238238
end
239239

240240
def build_query_options(positional_parameters: [])
241-
opts = { scan_consistency: CouchbaseOrm::N1ql.config[:scan_consistency] }
241+
opts = {
242+
scan_consistency: CouchbaseOrm::N1ql.config[:scan_consistency],
243+
adhoc: CouchbaseOrm::N1ql.config[:adhoc]
244+
}
242245
opts[:positional_parameters] = positional_parameters unless positional_parameters.empty?
243246
Couchbase::Options::Query.new(**opts)
244247
end

spec/relation_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,5 +501,10 @@ def self.active
501501
end
502502
end
503503
end
504+
505+
it "should use adhoc: false by default for prepared statement plan caching" do
506+
expect(Couchbase::Options::Query).to receive(:new).with(hash_including(adhoc: false)).and_call_original
507+
RelationModel.where(active: true).ids
508+
end
504509
end
505510

0 commit comments

Comments
 (0)