Skip to content

Commit

Permalink
Replace try/except with an if len > 8K solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Dreszer authored and hitz committed Feb 8, 2018
1 parent a829801 commit 60fef0d
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/snovault/elasticsearch/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
es_logger.setLevel(logging.ERROR)
log = logging.getLogger(__name__)
SEARCH_MAX = 99999 # OutOfMemoryError if too high
MAX_CLAUSES_FOR_ES = 8192

def includeme(config):
config.add_route('index', '/index')
Expand Down Expand Up @@ -369,8 +370,11 @@ def index(request):
if txn_count == 0:
return result

es.indices.refresh('_all')
try:
if len(updated) + len(renamed) > MAX_CLAUSES_FOR_ES:
invalidated = list(all_uuids(request.registry))
flush = True
else:
es.indices.refresh('_all')
res = es.search(index='_all', size=SEARCH_MAX, body={
'query': {
'bool': {
Expand Down Expand Up @@ -408,14 +412,6 @@ def index(request):
txn_count=txn_count,
first_txn_timestamp=first_txn.isoformat(),
)
except TransportError as e:
if e.error == "search_phase_execution_exception":
log.error("Error finding related uuids: updated:{} renamed:{}".format(len(updated), len(renamed)), exc_info=True)
invalidated = list(all_uuids(request.registry))
flush = True
log.info('Continuing with full reindexing...')
else:
raise

if invalidated and not dry_run:
# Exporting a snapshot mints a new xid, so only do so when required.
Expand Down

0 comments on commit 60fef0d

Please sign in to comment.