|
18 | 18 | -include("nouveau.hrl"). |
19 | 19 |
|
20 | 20 | %% public api |
21 | | --export([get_db_info/1]). |
| 21 | +-export([outdated/1, get_db_info/1]). |
22 | 22 |
|
23 | 23 | %% callbacks |
24 | 24 | -export([update/1]). |
|
47 | 47 | batch |
48 | 48 | }). |
49 | 49 |
|
| 50 | +outdated(#index{} = Index) -> |
| 51 | + {ok, Db} = couch_db:open_int(Index#index.dbname, []), |
| 52 | + try |
| 53 | + case open_or_create_index(Db, Index) of |
| 54 | + {ok, #{} = Info} -> |
| 55 | + #{<<"update_seq">> := IndexUpdateSeq, <<"purge_seq">> := IndexPurgeSeq} = Info, |
| 56 | + {DbUpdateSeq, DbPurgeSeq} = get_db_info(Db), |
| 57 | + DbUpdateSeq > IndexUpdateSeq orelse DbPurgeSeq > IndexPurgeSeq; |
| 58 | + {error, Reason} -> |
| 59 | + {error, Reason} |
| 60 | + end |
| 61 | + after |
| 62 | + couch_db:close(Db) |
| 63 | + end. |
| 64 | + |
50 | 65 | update(#index{} = Index) -> |
51 | 66 | {ok, Db} = couch_db:open_int(Index#index.dbname, []), |
52 | 67 | try |
@@ -219,12 +234,14 @@ open_or_create_index(Db, #index{} = Index) -> |
219 | 234 | get_db_info(#index{} = Index) -> |
220 | 235 | {ok, Db} = couch_db:open_int(Index#index.dbname, []), |
221 | 236 | try |
222 | | - UpdateSeq = couch_db:get_update_seq(Db), |
223 | | - PurgeSeq = couch_db:get_purge_seq(Db), |
224 | | - {UpdateSeq, PurgeSeq} |
| 237 | + get_db_info(Db) |
225 | 238 | after |
226 | 239 | couch_db:close(Db) |
227 | | - end. |
| 240 | + end; |
| 241 | +get_db_info(Db) -> |
| 242 | + UpdateSeq = couch_db:get_update_seq(Db), |
| 243 | + PurgeSeq = couch_db:get_purge_seq(Db), |
| 244 | + {UpdateSeq, PurgeSeq}. |
228 | 245 |
|
229 | 246 | index_definition(#index{} = Index, InitialPurgeSeq) -> |
230 | 247 | #{ |
|
0 commit comments