|
13 | 13 | -module(nouveau_plugin_couch_db).
|
14 | 14 |
|
15 | 15 | -export([
|
| 16 | + before_doc_update/3, |
16 | 17 | is_valid_purge_client/2,
|
17 | 18 | on_compact/2
|
18 | 19 | ]).
|
19 | 20 |
|
| 21 | +-include("nouveau.hrl"). |
| 22 | +-include_lib("couch/include/couch_db.hrl"). |
| 23 | + |
| 24 | +%% New index definitions get an explicit lucene version property, if missing. |
| 25 | +before_doc_update( |
| 26 | + #doc{id = <<?DESIGN_DOC_PREFIX, _/binary>>} = Doc, Db, ?INTERACTIVE_EDIT = UpdateType |
| 27 | +) -> |
| 28 | + #doc{body = {Fields}} = Doc, |
| 29 | + case couch_util:get_value(<<"nouveau">>, Fields) of |
| 30 | + {Indexes} when is_list(Indexes) -> |
| 31 | + [add_versions_to_doc(Doc), Db, UpdateType]; |
| 32 | + _ -> |
| 33 | + [Doc, Db, UpdateType] |
| 34 | + end; |
| 35 | +before_doc_update(Doc, Db, UpdateType) -> |
| 36 | + [Doc, Db, UpdateType]. |
| 37 | + |
| 38 | +add_versions_to_doc(#doc{} = Doc) -> |
| 39 | + #doc{body = {Fields0}} = Doc, |
| 40 | + {Indexes0} = couch_util:get_value(<<"nouveau">>, Fields0), |
| 41 | + Indexes1 = lists:map(fun add_version_to_index/1, Indexes0), |
| 42 | + Fields1 = couch_util:set_value(<<"nouveau">>, Fields0, {Indexes1}), |
| 43 | + Doc#doc{body = {Fields1}}. |
| 44 | + |
| 45 | +add_version_to_index({IndexName, {Index}}) -> |
| 46 | + case couch_util:get_value(<<"lucene_version">>, Index) of |
| 47 | + undefined -> |
| 48 | + {IndexName, |
| 49 | + {couch_util:set_value(<<"lucene_version">>, Index, ?TARGET_LUCENE_VERSION)}}; |
| 50 | + _ -> |
| 51 | + {IndexName, {Index}} |
| 52 | + end. |
| 53 | + |
20 | 54 | is_valid_purge_client(DbName, Props) ->
|
21 | 55 | nouveau_util:verify_index_exists(DbName, Props).
|
22 | 56 |
|
|
0 commit comments