move analyse function into indexinf function

This commit is contained in:
Sarah Hoffmann
2021-04-19 17:34:26 +02:00
parent c6bd2bb7fb
commit 18705b3f18

View File

@@ -13,12 +13,6 @@ from nominatim.db.async_connection import DBConnection
LOG = logging.getLogger() LOG = logging.getLogger()
def _analyse_db_if(conn, condition):
if condition:
with conn.cursor() as cur:
cur.execute('ANALYSE')
class Indexer: class Indexer:
""" Main indexing routine. """ Main indexing routine.
""" """
@@ -51,26 +45,31 @@ class Indexer:
database will be analysed at the appropriate places to database will be analysed at the appropriate places to
ensure that database statistics are updated. ensure that database statistics are updated.
""" """
conn = psycopg2.connect(self.dsn) with psycopg2.connect(self.dsn) as conn:
conn.autocommit = True conn.autocommit = True
if analyse:
def _analyse():
with conn.cursor() as cur:
cur.execute('ANALYSE')
else:
def _analyse():
pass
try:
self.index_by_rank(0, 4) self.index_by_rank(0, 4)
_analyse_db_if(conn, analyse) _analyse()
self.index_boundaries(0, 30) self.index_boundaries(0, 30)
_analyse_db_if(conn, analyse) _analyse()
self.index_by_rank(5, 25) self.index_by_rank(5, 25)
_analyse_db_if(conn, analyse) _analyse()
self.index_by_rank(26, 30) self.index_by_rank(26, 30)
_analyse_db_if(conn, analyse) _analyse()
self.index_postcodes() self.index_postcodes()
_analyse_db_if(conn, analyse) _analyse()
finally:
conn.close()
def index_boundaries(self, minrank, maxrank): def index_boundaries(self, minrank, maxrank):