X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/3ee8d9fa75011a5e259c3b58fce671b4ff0c35fc..6e908fb81c5a1d66e80d71c7b4676cacb1d8e801:/nominatim/indexer/indexer.py diff --git a/nominatim/indexer/indexer.py b/nominatim/indexer/indexer.py index d997e522..06c05e1d 100644 --- a/nominatim/indexer/indexer.py +++ b/nominatim/indexer/indexer.py @@ -119,6 +119,13 @@ class PostcodeRunner: WHERE place_id IN ({}) """.format(','.join((str(i) for i in ids))) + +def _analyse_db_if(conn, condition): + if condition: + with conn.cursor() as cur: + cur.execute('ANALYSE') + + class Indexer: """ Main indexing routine. """ @@ -142,7 +149,7 @@ class Indexer: for thread in self.threads: thread.close() - threads = [] + self.threads = [] def index_full(self, analyse=True): @@ -152,29 +159,26 @@ class Indexer: ensure that database statistics are updated. """ conn = psycopg2.connect(self.dsn) + conn.autocommit = True try: self.index_by_rank(0, 4) - self._analyse_db_if(conn, analyse) + _analyse_db_if(conn, analyse) self.index_boundaries(0, 30) - self._analyse_db_if(conn, analyse) + _analyse_db_if(conn, analyse) self.index_by_rank(5, 25) - self._analyse_db_if(conn, analyse) + _analyse_db_if(conn, analyse) self.index_by_rank(26, 30) - self._analyse_db_if(conn, analyse) + _analyse_db_if(conn, analyse) self.index_postcodes() - self._analyse_db_if(conn, analyse) + _analyse_db_if(conn, analyse) finally: conn.close() - def _analyse_db_if(self, conn, condition): - if condition: - with conn.cursor() as cur: - cur.execute('ANALYSE') def index_boundaries(self, minrank, maxrank): """ Index only administrative boundaries within the given rank range.