Skip to content

Commit b433c21

Browse files
committed
Add skip option to doc_fdi calback in quickjs scanner
Add a `skip` to the scanner to skip over a particular doc `fdi`. This makes it similar to the `db/2` and `doc_id/3` callbacks. Use this option in the quickjs plugin and add a test for it by inserting a deleted doc seeing that we skip over it.
1 parent 95fe201 commit b433c21

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/couch_quickjs/src/couch_quickjs_scanner_plugin.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ doc_id(#st{doc_cnt = C} = St, _DocId, _Db) ->
165165

166166
doc_fdi(#st{} = St, #full_doc_info{deleted = true}, _Db) ->
167167
% Skip deleted; don't even open the doc body
168-
{stop, St};
168+
{skip, St};
169169
doc_fdi(#st{} = St, #full_doc_info{}, _Db) ->
170170
{ok, St}.
171171

src/couch_quickjs/test/couch_quickjs_scanner_plugin_tests.erl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ couch_quickjs_scanner_plugin_test_() ->
3838
]
3939
}.
4040

41+
-define(DOC0, <<"doc0">>).
4142
-define(DOC1, <<"doc1">>).
4243
-define(DOC2, <<"doc2">>).
4344
-define(DOC3, <<"doc3">>).
@@ -55,6 +56,7 @@ setup() ->
5556
Ctx = test_util:start_couch([fabric, couch_scanner]),
5657
DbName = ?tempdb(),
5758
ok = fabric:create_db(DbName, [{q, "2"}, {n, "1"}]),
59+
ok = add_doc(DbName, ?DOC0, #{a => d, <<"_deleted">> => true}),
5860
ok = add_doc(DbName, ?DOC1, #{a => x}),
5961
ok = add_doc(DbName, ?DOC2, #{a => y}),
6062
ok = add_doc(DbName, ?DOC3, #{a => z}),

src/couch_scanner/src/couch_scanner_plugin.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
% Optional. If doc is not defined, then doc_fdi default action is {stop, St}.
133133
% If it is defined, the default action is {ok, St}.
134134
-callback doc_fdi(St :: term(), FDI :: #full_doc_info{}, Db :: term()) ->
135-
{ok | stop, St1 :: term()}.
135+
{ok | skip | stop, St1 :: term()}.
136136

137137
% Optional.
138138
-callback doc(St :: term(), Db :: term(), #doc{}) ->
@@ -404,6 +404,7 @@ scan_fdi(#full_doc_info{} = FDI, #st{} = St) ->
404404
St1 = St#st{pst = PSt1},
405405
case Go of
406406
ok -> scan_doc(FDI, St1);
407+
skip -> {ok, St1};
407408
stop -> {stop, St1}
408409
end.
409410

0 commit comments

Comments
 (0)