diff options
author | Tomeu Vizoso <tomeu@sugarlabs.org> | 2009-06-29 15:37:37 (GMT) |
---|---|---|
committer | Tomeu Vizoso <tomeu@sugarlabs.org> | 2009-06-29 15:37:37 (GMT) |
commit | 38c28ce52f366bd9fcd91f2abca5b9fe0313e474 (patch) | |
tree | c36db4e868d8aec1442be20aae3b382c7a1325d2 | |
parent | 987b48bb194acf301a968823ccbc079d3f734997 (diff) |
Rebuild index when an inconsistency between the index and the metadata is detected
-rw-r--r-- | src/carquinyol/datastore.py | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py index 369eff7..ff3875d 100644 --- a/src/carquinyol/datastore.py +++ b/src/carquinyol/datastore.py @@ -208,23 +208,42 @@ class DataStore(dbus.service.Object): if not layoutmanager.get_instance().index_updated: logging.warning('Index updating, returning all entries') + return self._find_all(query, properties) - uids = layoutmanager.get_instance().find_all() - count = len(uids) + entries = [] + for uid in uids: + entry_path = layoutmanager.get_instance().get_entry_path(uid) + if not os.path.exists(entry_path): + logging.warning('Inconsistency detected, returning all entries') + + layoutmanager.get_instance().index_updated = False + self._index_store.close_index() + self._index_store.remove_index() + self._index_store.open_index() + self._rebuild_index() + + return self._find_all(query, properties) - offset = query.get('offset', 0) - limit = query.get('limit', MAX_QUERY_LIMIT) - uids = uids[offset:offset + limit] + metadata = self._metadata_store.retrieve(uid, properties) + entries.append(metadata) + + logger.debug('find(): %r' % (time.time() - t)) + + return entries, count + + def _find_all(self, query, properties): + uids = layoutmanager.get_instance().find_all() + count = len(uids) + + offset = query.get('offset', 0) + limit = query.get('limit', MAX_QUERY_LIMIT) + uids = uids[offset:offset + limit] entries = [] for uid in uids: - if os.path.exists(layoutmanager.get_instance().get_entry_path(uid)): - metadata = self._metadata_store.retrieve(uid, properties) - entries.append(metadata) - else: - logging.debug('Skipping entry %r without metadata dir' % uid) - count = count - 1 - logger.debug('find(): %r' % (time.time() - t)) + metadata = self._metadata_store.retrieve(uid, properties) + entries.append(metadata) + return entries, count @dbus.service.method(DS_DBUS_INTERFACE, |