1 | import sets |
---|
2 | from CatalogEventQueue import ADDED, CHANGED, CHANGED_ADDED, REMOVED |
---|
3 | |
---|
4 | def _process_queue(self, queue, limit): |
---|
5 | """Process a single queue""" |
---|
6 | catalog = self.getZCatalog() |
---|
7 | |
---|
8 | if self.getProcessAllIndexes(): |
---|
9 | #idxs = None |
---|
10 | idxs = catalog.indexes() |
---|
11 | else: |
---|
12 | cat_indexes = sets.Set(catalog.indexes()) |
---|
13 | immediate_indexes = sets.Set(self._immediate_indexes) |
---|
14 | if not immediate_indexes or immediate_indexes==cat_indexes: |
---|
15 | idxs = catalog.indexes() # do all of 'em |
---|
16 | else: |
---|
17 | idxs = list(cat_indexes - immediate_indexes) |
---|
18 | events = queue.process(limit) |
---|
19 | count = 0 |
---|
20 | |
---|
21 | for uid, (t, event) in events.items(): |
---|
22 | if event is REMOVED: |
---|
23 | try: |
---|
24 | if cataloged(catalog, uid): |
---|
25 | catalog.uncatalog_object(uid) |
---|
26 | except (ConflictError, ClientDisconnected): |
---|
27 | raise |
---|
28 | except: |
---|
29 | logger.error('error uncataloging object', exc_info=True) |
---|
30 | else: |
---|
31 | # add or change |
---|
32 | if event is CHANGED and not cataloged(catalog, uid): |
---|
33 | continue |
---|
34 | # Note that the uid may be relative to the catalog. |
---|
35 | obj = catalog.unrestrictedTraverse(uid, None) |
---|
36 | if obj is not None: |
---|
37 | immediate_metadata = self.getImmediateMetadataUpdate() |
---|
38 | try: |
---|
39 | catalog.catalog_object( |
---|
40 | obj, uid, idxs=idxs, |
---|
41 | update_metadata=not immediate_metadata) |
---|
42 | except (ConflictError, ClientDisconnected): |
---|
43 | raise |
---|
44 | except: |
---|
45 | logger.error('error cataloging object', exc_info=True) |
---|
46 | |
---|
47 | count = count + 1 |
---|
48 | |
---|
49 | return count |
---|
50 | from Products.QueueCatalog.QueueCatalog import QueueCatalog |
---|
51 | QueueCatalog._process_queue = _process_queue |
---|