Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 65b32d2

Browse files
committed
Rework resulting object counting
1 parent 9e16caa commit 65b32d2

File tree

3 files changed

+33
-47
lines changed

3 files changed

+33
-47
lines changed

graphql/accessor_general.lua

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -901,10 +901,6 @@ local function process_tuple(self, state, tuple, opts)
901901
return true -- skip pivot item too
902902
end
903903

904-
-- XXX: implement retired flag for invoke resolve and don't save-restore
905-
-- resulting_object_cnt
906-
local saved_resulting_object_cnt = qcontext.statistics.resulting_object_cnt
907-
908904
-- make subrequests if needed
909905
for k, v in pairs(filter) do
910906
if obj[k] == nil then
@@ -918,8 +914,6 @@ local function process_tuple(self, state, tuple, opts)
918914
end
919915
end
920916

921-
qcontext.statistics.resulting_object_cnt = saved_resulting_object_cnt
922-
923917
-- filter out non-matching objects
924918
local match = utils.is_subtable(obj, filter) and
925919
match_using_re(obj, pcre)
@@ -934,9 +928,11 @@ local function process_tuple(self, state, tuple, opts)
934928
state.objs[#state.objs + 1] = obj
935929
state.count = state.count + 1
936930

937-
qcontext.statistics:objects_retired({
938-
retired_objects_cnt = 1,
939-
})
931+
if not opts.is_hidden then
932+
qcontext.statistics:objects_retired({
933+
retired_objects_cnt = 1,
934+
})
935+
end
940936

941937
if limit ~= nil and state.count >= limit then
942938
return false
@@ -1072,6 +1068,7 @@ local function prepare_select_internal(self, collection_name, from, filter,
10721068
default_unflatten_tuple = default_unflatten_tuple,
10731069
pcre = args.pcre,
10741070
resolveField = extra.resolveField,
1071+
is_hidden = extra.is_hidden,
10751072
}
10761073

10771074
-- assert that connection constraint applied only to objects got from the

graphql/bfs_executor.lua

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
--- do_filter = <boolean>,
131131
--- pivot_filter = <table>,
132132
--- resolveField = <function>,
133+
--- is_hidden = <boolean>,
133134
--- },
134135
--- collection_name = <string>,
135136
--- from = <...>,
@@ -305,7 +306,7 @@ local function generate_cache_only_request(prepared_resolve, field_type,
305306
-- cache_only_prepared_resolve is the same as prepared_resolve, but it does
306307
-- not require fetching connected objects to fetch and return this one
307308
local cache_only_prepared_resolve = field_type.prepare_resolve(
308-
object, local_args, info)
309+
object, local_args, info, {is_hidden = true})
309310
local cache_only_selections = filters_to_selections(
310311
bare_inner_type, filter)
311312
return {
@@ -451,6 +452,7 @@ end
451452
---
452453
--- @tparam table qcontext the following options:
453454
---
455+
--- * is_item_cache_only
454456
--- * qcontext: query-local storage for various purposes
455457
---
456458
--- @treturn table `prepared` of the following format:
@@ -478,6 +480,7 @@ end
478480
local function filter_object(object, object_type, selections, context, opts)
479481
local opts = opts or {}
480482
local qcontext = opts.qcontext
483+
local is_item_cache_only = opts.is_item_cache_only or false
481484

482485
local nullable_object_type = core_types.nullable(object_type)
483486

@@ -530,7 +533,7 @@ local function filter_object(object, object_type, selections, context, opts)
530533

531534
if field_type.prepare_resolve then
532535
local prepared_resolve = field_type.prepare_resolve(object, args,
533-
info)
536+
info, {is_hidden = is_item_cache_only})
534537

535538
fields_info[field_name] = {
536539
is_list = is_list,
@@ -577,6 +580,7 @@ local function filter_object_list(object_list, object_type, selections, context,
577580
opts)
578581
local opts = opts or {}
579582
local qcontext = opts.qcontext
583+
local is_item_cache_only = opts.is_item_cache_only or false
580584

581585
local nullable_object_type = core_types.nullable(object_type)
582586
assert(nullable_object_type.__type == 'List')
@@ -602,7 +606,7 @@ local function filter_object_list(object_list, object_type, selections, context,
602606

603607
for _, object in ipairs(object_list or {}) do
604608
local prepared = filter_object(object, object_type, selections, context,
605-
{qcontext = qcontext})
609+
{qcontext = qcontext, is_item_cache_only = is_item_cache_only})
606610
local cache_only_prepared_object = prepared.cache_only_prepared_object
607611
local prepared_object = prepared.prepared_object
608612
table.insert(cache_only_prepared_object_list,
@@ -634,29 +638,7 @@ local function invoke_resolve(prepared_object, context, opts)
634638
if field_info.prepared_resolve.is_calculated then
635639
object_or_list = field_info.prepared_resolve.objs
636640
else
637-
-- XXX: implement retired flag for invoke resolve and don't
638-
-- save-restore resulting_object_cnt
639-
local prepared_select
640-
local extra
641-
local select_state
642-
local saved_resulting_object_cnt
643-
if is_item_cache_only then
644-
-- prevent resulting_object_cnt from being affected by cache
645-
-- only requests
646-
prepared_select = field_info.prepared_resolve.prepared_select
647-
extra = prepared_select.extra
648-
select_state = prepared_select.select_state
649-
local qcontext = extra.qcontext
650-
saved_resulting_object_cnt =
651-
qcontext.statistics.resulting_object_cnt
652-
end
653641
object_or_list, object_type = field_info.prepared_resolve:invoke()
654-
if saved_resulting_object_cnt then
655-
extra.qcontext.statistics.resulting_object_cnt =
656-
saved_resulting_object_cnt
657-
select_state.qcontext.statistics.resulting_object_cnt =
658-
saved_resulting_object_cnt
659-
end
660642
end
661643
object_type = object_type or field_info.kind
662644
local selections = field_info.selections
@@ -667,7 +649,7 @@ local function invoke_resolve(prepared_object, context, opts)
667649
if field_info.is_list then
668650
local child_prepared_list = filter_object_list(
669651
object_or_list, object_type, selections, context,
670-
{qcontext = qcontext})
652+
{qcontext = qcontext, is_item_cache_only = is_item_cache_only})
671653
-- don't perform construction for cache_only objects
672654
local child_cache_only_prepared_object_list =
673655
child_prepared_list.cache_only_prepared_object_list
@@ -697,7 +679,8 @@ local function invoke_resolve(prepared_object, context, opts)
697679
end
698680
else
699681
local child_prepared = filter_object(object_or_list,
700-
object_type, selections, context, {qcontext = qcontext})
682+
object_type, selections, context, {qcontext = qcontext,
683+
is_item_cache_only = is_item_cache_only})
701684
-- don't perform construction for cache_only objects
702685
local child_cache_only_prepared_object =
703686
child_prepared.cache_only_prepared_object

graphql/convert_schema/resolve.lua

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ function resolve.gen_resolve_function(collection_name, connection,
121121
('performing a subrequest by the non-existent ' ..
122122
'field "%s" of the collection "%s"'):format(field_name,
123123
c.destination_collection))
124-
-- XXX: implement retired flag for invoke resolve and don't
125-
-- save-restore resulting_object_cnt
124+
local opts = table.copy(opts or {})
125+
opts.is_hidden = true
126126
return bare_destination_type.fields[field_name].resolve(
127127
object, filter, info, opts)
128128
end
@@ -132,9 +132,9 @@ function resolve.gen_resolve_function(collection_name, connection,
132132
-- genResolveField, arguments, accessor
133133
return function(parent, args_instance, info, opts)
134134
local opts = opts or {}
135-
assert(type(opts) == 'table',
136-
'opts must be nil or a table, got ' .. type(opts))
137-
-- no opts for now
135+
check(opts, 'opts', 'table')
136+
local is_hidden = opts.is_hidden or false
137+
check(is_hidden, 'is_hidden', 'boolean')
138138

139139
local from = gen_from_parameter(collection_name, parent, c)
140140

@@ -170,6 +170,7 @@ function resolve.gen_resolve_function(collection_name, connection,
170170
resolveField = resolveField, -- for subrequests
171171
extra_args = {},
172172
exp_tuple_count = exp_tuple_count,
173+
is_hidden = opts.is_hidden,
173174
}
174175

175176
-- object_args_instance will be passed to 'filter'
@@ -242,7 +243,12 @@ function resolve.gen_resolve_function_multihead(collection_name, connection,
242243
return res_var, var_idx, box_field_name
243244
end
244245

245-
return function(parent, _, info)
246+
return function(parent, _, info, opts)
247+
local opts = opts or {}
248+
check(opts, 'opts', 'table')
249+
local is_hidden = opts.is_hidden or false
250+
check(is_hidden, 'is_hidden', 'boolean')
251+
246252
-- If a parent object does not have all source fields (for any of
247253
-- variants) non-null then we do not resolve variant and just return
248254
-- box.NULL.
@@ -275,16 +281,16 @@ function resolve.gen_resolve_function_multihead(collection_name, connection,
275281
name = c.name,
276282
destination_collection = v.destination_collection,
277283
}
278-
local opts = {
284+
local gen_opts = {
279285
disable_dangling_check = disable_dangling_check,
280286
gen_prepare = gen_prepare,
281287
}
282288
-- XXX: generate a function (using gen_resolve_function) for each
283289
-- variant once at schema generation time
284290
if gen_prepare then
285291
local result = resolve.gen_resolve_function(collection_name,
286-
quazi_connection, destination_type, {}, accessor, opts)(
287-
parent, {}, info)
292+
quazi_connection, destination_type, {}, accessor, gen_opts)(
293+
parent, {}, info, opts)
288294
result.connection = quazi_connection
289295
result.invoke = function(prepared_resolve)
290296
local result = invoke_resolve(prepared_resolve)
@@ -294,8 +300,8 @@ function resolve.gen_resolve_function_multihead(collection_name, connection,
294300
return result
295301
else
296302
local result = resolve.gen_resolve_function(collection_name,
297-
quazi_connection, destination_type, {}, accessor, opts)(
298-
parent, {}, info)
303+
quazi_connection, destination_type, {}, accessor, gen_opts)(
304+
parent, {}, info, opts)
299305
-- This 'wrapping' is needed because we use 'select' on 'collection'
300306
-- GraphQL type and the result of the resolve function must be in
301307
-- {'collection_name': {result}} format to be avro-valid.

0 commit comments

Comments
 (0)