When repeatedly calling update_document(), each call instantiates a Searcher, which is expensive. The SegmentWriter already has a write lock on the index, so if the conditions are right, let's cache a Searcher, override its close() method to keep it open, and close it on _finish() if it's around.
I think this is safe, but I don't know enough about whoosh to be certain. All tests are still passing, and I didn't break any django-haystack tests with this change either.
When repeatedly calling
update_document()
, each call instantiates aSearcher
, which is expensive. TheSegmentWriter
already has a write lock on the index, so if the conditions are right, let's cache aSearcher
, override itsclose()
method to keep it open, and close it on_finish()
if it's around.I think this is safe, but I don't know enough about whoosh to be certain. All tests are still passing, and I didn't break any django-haystack tests with this change either.