Skip to content

Commit 6f4e28c

Browse files
author
Abdullah Yousufi
committed
Optimize searches_could_hit_incomplete_docs? to avoid datastore queries
1 parent 8820a5a commit 6f4e28c

37 files changed

Lines changed: 385 additions & 147 deletions

File tree

config/schema/artifacts/runtime_metadata.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,7 @@ index_definitions_by_name:
14611461
source: __self
14621462
timestamps.created_at:
14631463
source: __self
1464+
has_had_multiple_sources: false
14641465
route_with: id
14651466
components:
14661467
current_sources:
@@ -1508,6 +1509,7 @@ index_definitions_by_name:
15081509
source: widget
15091510
widget_workspace_id3:
15101511
source: widget
1512+
has_had_multiple_sources: true
15111513
route_with: id
15121514
electrical_parts:
15131515
current_sources:
@@ -1526,6 +1528,7 @@ index_definitions_by_name:
15261528
source: __self
15271529
voltage:
15281530
source: __self
1531+
has_had_multiple_sources: false
15291532
route_with: id
15301533
manufacturers:
15311534
current_sources:
@@ -1540,6 +1543,7 @@ index_definitions_by_name:
15401543
source: __self
15411544
name:
15421545
source: __self
1546+
has_had_multiple_sources: false
15431547
route_with: id
15441548
mechanical_parts:
15451549
current_sources:
@@ -1558,6 +1562,7 @@ index_definitions_by_name:
15581562
source: __self
15591563
name:
15601564
source: __self
1565+
has_had_multiple_sources: false
15611566
route_with: id
15621567
sponsors:
15631568
current_sources:
@@ -1567,6 +1572,7 @@ index_definitions_by_name:
15671572
source: __self
15681573
name:
15691574
source: __self
1575+
has_had_multiple_sources: false
15701576
route_with: id
15711577
teams:
15721578
current_sources:
@@ -2446,6 +2452,7 @@ index_definitions_by_name:
24462452
source: __self
24472453
won_championships_at:
24482454
source: __self
2455+
has_had_multiple_sources: false
24492456
rollover:
24502457
frequency: yearly
24512458
timestamp_field_path: formed_on
@@ -2492,6 +2499,7 @@ index_definitions_by_name:
24922499
source: __self
24932500
widget_tags:
24942501
source: __self
2502+
has_had_multiple_sources: false
24952503
rollover:
24962504
frequency: yearly
24972505
timestamp_field_path: introduced_on
@@ -2508,6 +2516,7 @@ index_definitions_by_name:
25082516
source: __self
25092517
widget.id:
25102518
source: __self
2519+
has_had_multiple_sources: false
25112520
route_with: id
25122521
widgets:
25132522
current_sources:
@@ -2615,6 +2624,7 @@ index_definitions_by_name:
26152624
source: __self
26162625
workspace_name:
26172626
source: workspace
2627+
has_had_multiple_sources: true
26182628
rollover:
26192629
frequency: yearly
26202630
timestamp_field_path: created_at

config/schema/artifacts_with_apollo/runtime_metadata.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,7 @@ index_definitions_by_name:
14901490
source: __self
14911491
timestamps.created_at:
14921492
source: __self
1493+
has_had_multiple_sources: false
14931494
route_with: id
14941495
components:
14951496
current_sources:
@@ -1537,6 +1538,7 @@ index_definitions_by_name:
15371538
source: widget
15381539
widget_workspace_id3:
15391540
source: widget
1541+
has_had_multiple_sources: true
15401542
route_with: id
15411543
electrical_parts:
15421544
current_sources:
@@ -1555,6 +1557,7 @@ index_definitions_by_name:
15551557
source: __self
15561558
voltage:
15571559
source: __self
1560+
has_had_multiple_sources: false
15581561
route_with: id
15591562
manufacturers:
15601563
current_sources:
@@ -1569,6 +1572,7 @@ index_definitions_by_name:
15691572
source: __self
15701573
name:
15711574
source: __self
1575+
has_had_multiple_sources: false
15721576
route_with: id
15731577
mechanical_parts:
15741578
current_sources:
@@ -1587,6 +1591,7 @@ index_definitions_by_name:
15871591
source: __self
15881592
name:
15891593
source: __self
1594+
has_had_multiple_sources: false
15901595
route_with: id
15911596
sponsors:
15921597
current_sources:
@@ -1596,6 +1601,7 @@ index_definitions_by_name:
15961601
source: __self
15971602
name:
15981603
source: __self
1604+
has_had_multiple_sources: false
15991605
route_with: id
16001606
teams:
16011607
current_sources:
@@ -2475,6 +2481,7 @@ index_definitions_by_name:
24752481
source: __self
24762482
won_championships_at:
24772483
source: __self
2484+
has_had_multiple_sources: false
24782485
rollover:
24792486
frequency: yearly
24802487
timestamp_field_path: formed_on
@@ -2521,6 +2528,7 @@ index_definitions_by_name:
25212528
source: __self
25222529
widget_tags:
25232530
source: __self
2531+
has_had_multiple_sources: false
25242532
rollover:
25252533
frequency: yearly
25262534
timestamp_field_path: introduced_on
@@ -2537,6 +2545,7 @@ index_definitions_by_name:
25372545
source: __self
25382546
widget.id:
25392547
source: __self
2548+
has_had_multiple_sources: false
25402549
route_with: id
25412550
widgets:
25422551
current_sources:
@@ -2644,6 +2653,7 @@ index_definitions_by_name:
26442653
source: __self
26452654
workspace_name:
26462655
source: workspace
2656+
has_had_multiple_sources: true
26472657
rollover:
26482658
frequency: yearly
26492659
timestamp_field_path: created_at

config/schema/widgets.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
i.rollover :yearly, "created_at"
146146
i.route_with "workspace_id"
147147
i.default_sort "created_at", :desc
148+
i.has_had_multiple_sources!
148149
end
149150

150151
t.derive_indexed_type_fields "WidgetCurrency", from_id: "cost.currency", route_with: "cost_currency_primary_continent", rollover_with: "cost_currency_introduced_on" do |derive|
@@ -280,6 +281,7 @@
280281

281282
t.index "components" do |i|
282283
i.default_sort "created_at", :desc
284+
i.has_had_multiple_sources!
283285
end
284286
end
285287

elasticgraph-admin/spec/integration/elastic_graph/admin/index_definition_configurator/for_index_template_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ def concrete_index_name_for_now(base_index_name)
2020

2121
prepend Module.new {
2222
def schema_def(**options)
23-
configure_index = ->(index) { index.rollover :monthly, "created_at" }
23+
original_configure_index = options.delete(:configure_index)
24+
configure_index = ->(index) {
25+
index.rollover :monthly, "created_at"
26+
original_configure_index&.call(index)
27+
}
2428
super(configure_index: configure_index, **options)
2529
end
2630
}

elasticgraph-admin/spec/integration/elastic_graph/admin/index_definition_configurator/shared_examples.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ def simulate_presence_of_extra_setting(admin, index_definition_name, name, value
231231
t.field "owner_name", "String" do |f|
232232
f.sourced_from "owner", "name"
233233
end
234+
end,
235+
configure_index: lambda do |i|
236+
i.has_had_multiple_sources!
234237
end
235238
))
236239
}.to change { get_index_definition_configuration(unique_index_name).dig("mappings", "_meta") }
@@ -247,6 +250,9 @@ def simulate_presence_of_extra_setting(admin, index_definition_name, name, value
247250
t.field "owner_name", "String" do |f|
248251
f.sourced_from "owner2", "name"
249252
end
253+
end,
254+
configure_index: lambda do |i|
255+
i.has_had_multiple_sources!
250256
end
251257
))
252258
}.to change { get_index_definition_configuration(unique_index_name).dig("mappings", "_meta") }

elasticgraph-apollo/spec/unit/elastic_graph/apollo/schema_definition_spec.rb

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,17 @@ def self.with_both_casing_forms(&block)
445445
schema.object_type "Component" do |t|
446446
t.field "id", "ID"
447447
t.field "number", "String"
448-
t.index "components"
448+
t.index "components" do |i|
449+
i.has_had_multiple_sources!
450+
end
449451
end
450452

451453
schema.object_type "Widget" do |t|
452454
t.field "id", "ID"
453455
t.field "number", "Int"
454-
t.index "widgets"
456+
t.index "widgets" do |i|
457+
i.has_had_multiple_sources!
458+
end
455459
end
456460

457461
if define_manual_union_type
@@ -516,7 +520,9 @@ def self.with_both_casing_forms(&block)
516520
schema.object_type "NotABuiltInType" do |t|
517521
t.field "id", "ID!"
518522
t.field "name", "String"
519-
t.index "widgets"
523+
t.index "widgets" do |i|
524+
i.has_had_multiple_sources!
525+
end
520526
end
521527

522528
schema.tag_built_in_types_with("tag1")
@@ -621,7 +627,9 @@ def self.with_both_casing_forms(&block)
621627
f.documentation "A component entity reference."
622628
end
623629

624-
t.index "widgets"
630+
t.index "widgets" do |i|
631+
i.has_had_multiple_sources!
632+
end
625633
end
626634
end
627635

@@ -712,7 +720,9 @@ def self.with_both_casing_forms(&block)
712720
f.documentation "Component entity references."
713721
end
714722

715-
t.index "widgets"
723+
t.index "widgets" do |i|
724+
i.has_had_multiple_sources!
725+
end
716726
end
717727
end
718728

@@ -801,7 +811,9 @@ def self.with_both_casing_forms(&block)
801811
f.directive "deprecated"
802812
end
803813

804-
t.index "widgets"
814+
t.index "widgets" do |i|
815+
i.has_had_multiple_sources!
816+
end
805817
end
806818
end
807819

@@ -895,7 +907,9 @@ def self.with_both_casing_forms(&block)
895907
f.directive "deprecated"
896908
end
897909

898-
t.index "widgets"
910+
t.index "widgets" do |i|
911+
i.has_had_multiple_sources!
912+
end
899913
end
900914
end
901915

@@ -985,7 +999,9 @@ def self.with_both_casing_forms(&block)
985999
t.field "id", "ID"
9861000
t.field "component_id", "ID"
9871001
t.apollo_entity_ref_field "component", "String", id_field_name_in_index: "component_id"
988-
t.index "widgets"
1002+
t.index "widgets" do |i|
1003+
i.has_had_multiple_sources!
1004+
end
9891005
end
9901006
end
9911007
}.to raise_error Errors::SchemaError, a_string_including(
@@ -1001,7 +1017,9 @@ def self.with_both_casing_forms(&block)
10011017
t.field "id", "ID"
10021018
t.field "component_id", "ID"
10031019
t.apollo_entity_ref_field "component", "Component", id_field_name_in_index: "component_id"
1004-
t.index "widgets"
1020+
t.index "widgets" do |i|
1021+
i.has_had_multiple_sources!
1022+
end
10051023
end
10061024

10071025
schema.object_type "Component" do |t|
@@ -1022,7 +1040,9 @@ def self.with_both_casing_forms(&block)
10221040
t.field "id", "ID"
10231041
t.field "component_id", "ID"
10241042
t.apollo_entity_ref_field "component", "Component", id_field_name_in_index: "component_id"
1025-
t.index "widgets"
1043+
t.index "widgets" do |i|
1044+
i.has_had_multiple_sources!
1045+
end
10261046
end
10271047

10281048
schema.object_type "Component" do |t|
@@ -1061,7 +1081,9 @@ def self.with_both_casing_forms(&block)
10611081
t.field "id", "ID"
10621082
t.field "component_id", "ID"
10631083
t.apollo_entity_ref_field "component", "Component", id_field_name_in_index: "component_id2"
1064-
t.index "widgets"
1084+
t.index "widgets" do |i|
1085+
i.has_had_multiple_sources!
1086+
end
10651087
end
10661088

10671089
schema.object_type "Component" do |t|
@@ -1080,7 +1102,9 @@ def self.with_both_casing_forms(&block)
10801102
t.field "id", "ID"
10811103
t.field "component_id", "String"
10821104
t.apollo_entity_ref_field "component", "Component", id_field_name_in_index: "component_id"
1083-
t.index "widgets"
1105+
t.index "widgets" do |i|
1106+
i.has_had_multiple_sources!
1107+
end
10841108
end
10851109

10861110
schema.object_type "Component" do |t|
@@ -1099,7 +1123,9 @@ def self.with_both_casing_forms(&block)
10991123
t.field "id", "ID"
11001124
t.field "component_id", "ID"
11011125
t.apollo_entity_ref_paginated_collection_field "component", "Component", id_field_name_in_index: "component_id"
1102-
t.index "widgets"
1126+
t.index "widgets" do |i|
1127+
i.has_had_multiple_sources!
1128+
end
11031129
end
11041130

11051131
schema.object_type "Component" do |t|
@@ -1157,7 +1183,9 @@ def self.with_both_casing_forms(&block)
11571183
f.tag_with "public"
11581184
end
11591185

1160-
t.index "widgets"
1186+
t.index "widgets" do |i|
1187+
i.has_had_multiple_sources!
1188+
end
11611189
end
11621190
end
11631191

elasticgraph-datastore_core/lib/elastic_graph/datastore_core/index_definition.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def self.with(name:, runtime_metadata:, config:, datastore_clients_by_name:, sch
3232
fields_by_path: runtime_metadata.fields_by_path,
3333
env_index_config: env_index_config,
3434
defined_clusters: config.clusters.keys.to_set,
35-
datastore_clients_by_name: datastore_clients_by_name
35+
datastore_clients_by_name: datastore_clients_by_name,
36+
has_had_multiple_sources: runtime_metadata.has_had_multiple_sources
3637
}
3738

3839
if (rollover = runtime_metadata.rollover)

0 commit comments

Comments
 (0)