mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-03-11 05:14:07 +00:00
integrate analyse of indexing into nominatim tool
This commit is contained in:
49
nominatim/tools/admin.py
Normal file
49
nominatim/tools/admin.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""
|
||||
Functions for database analysis and maintenance.
|
||||
"""
|
||||
import logging
|
||||
|
||||
from ..errors import UsageError
|
||||
|
||||
LOG = logging.getLogger()
|
||||
|
||||
def analyse_indexing(conn, osm_id=None, place_id=None):
|
||||
""" Analyse indexing of a single Nominatim object.
|
||||
"""
|
||||
with conn.cursor() as cur:
|
||||
if osm_id:
|
||||
osm_type = osm_id[0].upper()
|
||||
if osm_type not in 'NWR' or not osm_id[1:].isdigit():
|
||||
LOG.fatal('OSM ID must be of form <N|W|R><id>. Got: %s', osm_id)
|
||||
raise UsageError("OSM ID parameter badly formatted")
|
||||
cur.execute('SELECT place_id FROM placex WHERE osm_type = %s AND osm_id = %s',
|
||||
(osm_type, osm_id[1:]))
|
||||
|
||||
if cur.rowcount < 1:
|
||||
LOG.fatal("OSM object %s not found in database.", osm_id)
|
||||
raise UsageError("OSM object not found")
|
||||
|
||||
place_id = cur.fetchone()[0]
|
||||
|
||||
if place_id is None:
|
||||
LOG.fatal("No OSM object given to index.")
|
||||
raise UsageError("OSM object not found")
|
||||
|
||||
cur.execute("update placex set indexed_status = 2 where place_id = %s",
|
||||
(place_id, ))
|
||||
|
||||
cur.execute("""SET auto_explain.log_min_duration = '0';
|
||||
SET auto_explain.log_analyze = 'true';
|
||||
SET auto_explain.log_nested_statements = 'true';
|
||||
LOAD 'auto_explain';
|
||||
SET client_min_messages = LOG;
|
||||
SET log_min_messages = FATAL""")
|
||||
|
||||
cur.execute("update placex set indexed_status = 0 where place_id = %s",
|
||||
(place_id, ))
|
||||
|
||||
# we do not want to keep the results
|
||||
conn.rollback()
|
||||
|
||||
for msg in conn.notices:
|
||||
print(msg)
|
||||
Reference in New Issue
Block a user