From fadcb67db419a98193f0ef45b5ac93795bc6ef59 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Mon, 29 Jun 2009 15:37:37 +0000 Subject: Rebuild index when an inconsistency between the index and the metadata is detected --- diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py index 343f9ba..b1dd3e5 100644 --- a/src/carquinyol/datastore.py +++ b/src/carquinyol/datastore.py @@ -205,23 +205,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, -- cgit v0.9.1