[gen] Cleaner and more robust approach when using Zope database indexes.
This commit is contained in:
parent
5c2d94236f
commit
c2eaab4b44
6 changed files with 75 additions and 30 deletions
|
@ -168,20 +168,41 @@ class ToolWrapper(AbstractWrapper):
|
|||
# reindex all Appy-managed objects, ie those in folders "config"
|
||||
# and "data".
|
||||
# First, clear the catalog.
|
||||
self.log('Recomputing the whole catalog...')
|
||||
app = self.o.getParentNode()
|
||||
app.catalog._catalog.clear()
|
||||
app.config.reindex()
|
||||
nb = 1
|
||||
failed = []
|
||||
for obj in app.config.objectValues():
|
||||
nb += self.refreshCatalog(startObject=obj)
|
||||
subNb, subFailed = self.refreshCatalog(startObject=obj)
|
||||
nb += subNb
|
||||
failed += subFailed
|
||||
try:
|
||||
app.config.reindex()
|
||||
except:
|
||||
failed.append(app.config)
|
||||
# Then, refresh objects in the "data" folder.
|
||||
for obj in app.data.objectValues():
|
||||
nb += self.refreshCatalog(startObject=obj)
|
||||
print '%d object(s) were reindexed.' % nb
|
||||
subNb, subFailed = self.refreshCatalog(startObject=obj)
|
||||
nb += subNb
|
||||
failed += subFailed
|
||||
# Re-try to index all objects for which reindexation has failed.
|
||||
for obj in failed: obj.reindex()
|
||||
if failed:
|
||||
failMsg = ' (%d retried)' % len(failed)
|
||||
else:
|
||||
failMsg = ''
|
||||
self.log('%d object(s) were reindexed%s.' % (nb, failMsg))
|
||||
else:
|
||||
startObject.reindex()
|
||||
nb = 1
|
||||
failed = []
|
||||
for obj in startObject.objectValues():
|
||||
nb += self.refreshCatalog(startObject=obj)
|
||||
return nb
|
||||
subNb, subFailed = self.refreshCatalog(startObject=obj)
|
||||
nb += subNb
|
||||
failed += subFailed
|
||||
try:
|
||||
startObject.reindex()
|
||||
except Exception, e:
|
||||
failed.append(startObject)
|
||||
return nb, failed
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
# ------------------------------------------------------------------------------
|
||||
import os, os.path, mimetypes
|
||||
import appy.pod
|
||||
from appy.gen import Type, Search, Ref, String, WorkflowAnonymous
|
||||
from appy.gen import Type, Search, Ref, String, WorkflowAnonymous, \
|
||||
defaultIndexes
|
||||
from appy.gen.utils import createObject
|
||||
from appy.shared.utils import getOsTempFolder, executeCommand, \
|
||||
normalizeString, sequenceTypes
|
||||
|
@ -59,6 +60,24 @@ class AbstractWrapper(object):
|
|||
if not res: res = cfg.defaultAddRoles
|
||||
return res
|
||||
|
||||
@classmethod
|
||||
def getIndexes(klass, includeDefaults=True):
|
||||
'''Returns a dict whose keys are the names of the indexes that are
|
||||
applicable to instances of this class, and whose values are the
|
||||
(Zope) types of those indexes.'''
|
||||
# Start with the standard indexes applicable for any Appy class.
|
||||
if includeDefaults:
|
||||
res = defaultIndexes.copy()
|
||||
else:
|
||||
res = {}
|
||||
# Add the indexed fields found on this class
|
||||
for field in klass.__fields__:
|
||||
if not field.indexed or (field.name == 'title'): continue
|
||||
n = field.name
|
||||
indexName = 'get%s%s' % (n[0].upper(), n[1:])
|
||||
res[indexName] = field.getIndexType()
|
||||
return res
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Instance methods
|
||||
# --------------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue