Skip to content

Commit

Permalink
Consolidate code for general usage of _convert
Browse files Browse the repository at this point in the history
  • Loading branch information
andbag committed Apr 12, 2019
1 parent 64b1f3b commit c1dcee1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 46 deletions.
47 changes: 1 addition & 46 deletions src/Products/PluginIndexes/DateIndex/DateIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,51 +112,6 @@ def clear(self):
else:
self._increment_counter()

def index_object(self, documentId, obj, threshold=None):
"""index an object, normalizing the indexed value to an integer
o Normalized value has granularity of one minute.
o Objects which have 'None' as indexed value are *omitted*,
by design.
"""
returnStatus = 0

try:
date_attr = getattr(obj, self.id)
if safe_callable(date_attr):
date_attr = date_attr()

ConvertedDate = self._convert(value=date_attr, default=_marker)
except AttributeError:
ConvertedDate = _marker

oldConvertedDate = self._unindex.get(documentId, _marker)

if ConvertedDate != oldConvertedDate:
if oldConvertedDate is not _marker:
self.removeForwardIndexEntry(oldConvertedDate, documentId)
if ConvertedDate is _marker:
try:
del self._unindex[documentId]
except ConflictError:
raise
except Exception:
LOG.error('Should not happen: ConvertedDate was there,'
' now it\'s not, for document'
' with id %s', documentId)

if ConvertedDate is not _marker:
self.insertForwardIndexEntry(ConvertedDate, documentId)
self._unindex[documentId] = ConvertedDate

returnStatus = 1

if returnStatus > 0:
self._increment_counter()

return returnStatus

def _convert(self, value, default=None):
"""Convert Date/Time value to our internal representation"""
if isinstance(value, DateTime):
Expand Down Expand Up @@ -186,7 +141,7 @@ def _convert(self, value, default=None):

# flatten to precision
if self.precision > 1:
t_val = t_val - (t_val % self.precision)
t_val = t_val - (int(t_val) % self.precision)

t_val = int(t_val)

Expand Down
2 changes: 2 additions & 0 deletions src/Products/PluginIndexes/unindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ def _index_object(self, documentId, obj, threshold=None, attr=''):
# "object has default comparison" and won't let it be indexed.
return 0

datum = self._convert(datum, default=_marker)

# We don't want to do anything that we don't have to here, so we'll
# check to see if the new and existing information is the same.
oldDatum = self._unindex.get(documentId, _marker)
Expand Down

0 comments on commit c1dcee1

Please sign in to comment.