mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-03-07 02:24:08 +00:00
consolidate warm and db-check into single admin command
This commit is contained in:
@@ -265,45 +265,6 @@ class UpdateAddData:
|
||||
return run_legacy_script(*params, nominatim_env=args)
|
||||
|
||||
|
||||
class AdminCheckDatabase:
|
||||
"""\
|
||||
Check that the database is complete and operational.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def add_args(parser):
|
||||
pass # No options
|
||||
|
||||
@staticmethod
|
||||
def run(args):
|
||||
return run_legacy_script('check_import_finished.php', nominatim_env=args)
|
||||
|
||||
|
||||
class AdminWarm:
|
||||
"""\
|
||||
Warm database caches for search and reverse queries.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def add_args(parser):
|
||||
group = parser.add_argument_group('Target arguments')
|
||||
group.add_argument('--search-only', action='store_const', dest='target',
|
||||
const='search',
|
||||
help="Only pre-warm tables for search queries")
|
||||
group.add_argument('--reverse-only', action='store_const', dest='target',
|
||||
const='reverse',
|
||||
help="Only pre-warm tables for reverse queries")
|
||||
|
||||
@staticmethod
|
||||
def run(args):
|
||||
params = ['warm.php']
|
||||
if args.target == 'reverse':
|
||||
params.append('--reverse-only')
|
||||
if args.target == 'search':
|
||||
params.append('--search-only')
|
||||
return run_legacy_script(*params, nominatim_env=args)
|
||||
|
||||
|
||||
class QueryExport:
|
||||
"""\
|
||||
Export addresses as CSV file from the database.
|
||||
@@ -393,15 +354,14 @@ def nominatim(**kwargs):
|
||||
parser.add_subcommand('freeze', SetupFreeze)
|
||||
parser.add_subcommand('replication', clicmd.UpdateReplication)
|
||||
|
||||
parser.add_subcommand('check-database', AdminCheckDatabase)
|
||||
parser.add_subcommand('warm', AdminWarm)
|
||||
|
||||
parser.add_subcommand('special-phrases', SetupSpecialPhrases)
|
||||
|
||||
parser.add_subcommand('add-data', UpdateAddData)
|
||||
parser.add_subcommand('index', clicmd.UpdateIndex)
|
||||
parser.add_subcommand('refresh', clicmd.UpdateRefresh)
|
||||
|
||||
parser.add_subcommand('admin', clicmd.AdminFuncs)
|
||||
|
||||
parser.add_subcommand('export', QueryExport)
|
||||
parser.add_subcommand('serve', AdminServe)
|
||||
|
||||
|
||||
@@ -6,3 +6,4 @@ from .replication import UpdateReplication
|
||||
from .api import APISearch, APIReverse, APILookup, APIDetails, APIStatus
|
||||
from .index import UpdateIndex
|
||||
from .refresh import UpdateRefresh
|
||||
from .admin import AdminFuncs
|
||||
|
||||
49
nominatim/clicmd/admin.py
Normal file
49
nominatim/clicmd/admin.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""
|
||||
Implementation of the 'admin' subcommand.
|
||||
"""
|
||||
from ..tools.exec_utils import run_legacy_script
|
||||
|
||||
# Do not repeat documentation of subcommand classes.
|
||||
# pylint: disable=C0111
|
||||
# Using non-top-level imports to avoid eventually unused imports.
|
||||
# pylint: disable=E0012,C0415
|
||||
|
||||
class AdminFuncs:
|
||||
"""\
|
||||
Analyse and maintain the database.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def add_args(parser):
|
||||
group = parser.add_argument_group('Admin task arguments')
|
||||
group.add_argument('--warm', action='store_true',
|
||||
help='Warm database caches for search and reverse queries.')
|
||||
group.add_argument('--check-database', action='store_true',
|
||||
help='Check that the database is complete and operational.')
|
||||
group = parser.add_argument_group('Arguments for cache warming')
|
||||
group.add_argument('--search-only', action='store_const', dest='target',
|
||||
const='search',
|
||||
help="Only pre-warm tables for search queries")
|
||||
group.add_argument('--reverse-only', action='store_const', dest='target',
|
||||
const='reverse',
|
||||
help="Only pre-warm tables for reverse queries")
|
||||
|
||||
@staticmethod
|
||||
def run(args):
|
||||
if args.warm:
|
||||
AdminFuncs._warm(args)
|
||||
|
||||
if args.check_database:
|
||||
run_legacy_script('check_import_finished.php', nominatim_env=args)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _warm(args):
|
||||
params = ['warm.php']
|
||||
if args.target == 'reverse':
|
||||
params.append('--reverse-only')
|
||||
if args.target == 'search':
|
||||
params.append('--search-only')
|
||||
return run_legacy_script(*params, nominatim_env=args)
|
||||
Reference in New Issue
Block a user