nickva commented on code in PR #5617: URL: https://github.com/apache/couchdb/pull/5617#discussion_r2257538188
########## src/nouveau/src/nouveau_rpc.erl: ########## @@ -24,49 +24,65 @@ -include("nouveau.hrl"). -import(nouveau_util, [index_path/1]). +-define(nouveau_update_latency, nouveau_update_latency). + search(DbName, #index{} = Index0, QueryArgs0) -> %% Incorporate the shard name into the record. Index1 = Index0#index{dbname = DbName}, - %% get minimum seqs for search - {MinUpdateSeq, MinPurgeSeq} = nouveau_index_updater:get_db_info(Index1), + Update = maps:get(update, QueryArgs0, true), %% Incorporate min seqs into the query args. - QueryArgs1 = QueryArgs0#{ - min_update_seq => MinUpdateSeq, - min_purge_seq => MinPurgeSeq - }, - Update = maps:get(update, QueryArgs1, true), - - %% check if index is up to date - T0 = erlang:monotonic_time(), - case Update andalso nouveau_index_updater:outdated(Index1) of - true -> - case nouveau_index_manager:update_index(Index1) of - ok -> - ok; - {error, Reason} -> - rexi:reply({error, Reason}) - end; - false -> - ok; - {error, Reason} -> - rexi:reply({error, Reason}) - end, - T1 = erlang:monotonic_time(), - UpdateLatency = erlang:convert_time_unit(T1 - T0, native, millisecond), + QueryArgs1 = + case Update of + true -> + %% get minimum seqs for search + {MinUpdateSeq, MinPurgeSeq} = nouveau_index_updater:get_db_info(Index1), + QueryArgs0#{ + min_update_seq => MinUpdateSeq, + min_purge_seq => MinPurgeSeq + }; + false -> + QueryArgs0#{ + min_update_seq => 0, + min_purge_seq => 0 + } + end, %% Run the search case nouveau_api:search(Index1, QueryArgs1) of {ok, Response} -> - rexi:reply({ok, Response#{update_latency => UpdateLatency}}); - {error, stale_index} -> - %% try again. - search(DbName, Index0, QueryArgs0); + rexi:reply({ok, Response#{update_latency => get_update_latency()}}); Review Comment: In general we'd clean up the process dict but in this case we always run in a spawned rexi worker, so probably doesn't matter? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@couchdb.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org