[Zope3-checkins] SVN: Zope3/trunk/src/zope/index/field/ Optimze
FieldIndex.
Jürgen Kartnaller
juergen at kartnaller.at
Tue Apr 3 08:52:55 EDT 2007
Log message for revision 73990:
Optimze FieldIndex.
Only unindex_doc if the value changed in index_doc.
Changed:
U Zope3/trunk/src/zope/index/field/README.txt
U Zope3/trunk/src/zope/index/field/index.py
-=-
Modified: Zope3/trunk/src/zope/index/field/README.txt
===================================================================
--- Zope3/trunk/src/zope/index/field/README.txt 2007-04-03 11:35:49 UTC (rev 73989)
+++ Zope3/trunk/src/zope/index/field/README.txt 2007-04-03 12:52:55 UTC (rev 73990)
@@ -20,14 +20,14 @@
>>> index.index_doc(8, 43)
>>> index.index_doc(9, 15)
-Fied indexes are searched with apply. The argument is a tuple
+Field indexes are searched with apply. The argument is a tuple
with a minimum and maximum value:
>>> index.apply((30, 70))
IFSet([3, 4, 5, 7, 8])
A common mistake is to pass a single value. If anything other than a
-tw-tuple is passed, a type error is raised:
+two-tuple is passed, a type error is raised:
>>> index.apply('hi')
Traceback (most recent call last):
@@ -138,3 +138,31 @@
>>> index.apply((None, None))
IFSet([0, 1, 2, 4, 6, 7, 8, 9])
+
+
+Optimizations
+-------------
+
+There is an optimization which makes sure that nothing is changed in the
+internal data structures if the value of the ducument was not changed.
+
+To test this optimization we patch the index instance to make sure unindex_doc
+is not called.
+
+ >>> def unindex_doc(doc_id):
+ ... raise KeyError
+ >>> index.unindex_doc = unindex_doc
+
+Now we get a KeyError if we try to change the value.
+
+ >>> index.index_doc(9, 14)
+ Traceback (most recent call last):
+ ...
+ KeyError
+
+Leaving the value unchange doesn't call unindex_doc.
+
+ >>> index.index_doc(9, 15)
+ >>> index.apply((15, 15))
+ IFSet([9])
+
Modified: Zope3/trunk/src/zope/index/field/index.py
===================================================================
--- Zope3/trunk/src/zope/index/field/index.py 2007-04-03 11:35:49 UTC (rev 73989)
+++ Zope3/trunk/src/zope/index/field/index.py 2007-04-03 12:52:55 UTC (rev 73990)
@@ -57,6 +57,9 @@
"""See interface IInjection"""
rev_index = self._rev_index
if docid in rev_index:
+ if docid in self._fwd_index.get(value, ()):
+ # no need to index the doc, its already up to date
+ return
# unindex doc if present
self.unindex_doc(docid)
More information about the Zope3-Checkins
mailing list