2 Implementation of the 'admin' subcommand.
4 from ..tools.exec_utils import run_legacy_script
5 from ..db.connection import connect
7 # Do not repeat documentation of subcommand classes.
8 # pylint: disable=C0111
9 # Using non-top-level imports to avoid eventually unused imports.
10 # pylint: disable=E0012,C0415
14 Analyse and maintain the database.
19 group = parser.add_argument_group('Admin task arguments')
20 group.add_argument('--warm', action='store_true',
21 help='Warm database caches for search and reverse queries.')
22 group.add_argument('--check-database', action='store_true',
23 help='Check that the database is complete and operational.')
24 group.add_argument('--analyse-indexing', action='store_true',
25 help='Print performance analysis of the indexing process.')
26 group = parser.add_argument_group('Arguments for cache warming')
27 group.add_argument('--search-only', action='store_const', dest='target',
29 help="Only pre-warm tables for search queries")
30 group.add_argument('--reverse-only', action='store_const', dest='target',
32 help="Only pre-warm tables for reverse queries")
33 group = parser.add_argument_group('Arguments for index anaysis')
34 mgroup = group.add_mutually_exclusive_group()
35 mgroup.add_argument('--osm-id', type=str,
36 help='Analyse indexing of the given OSM object')
37 mgroup.add_argument('--place-id', type=int,
38 help='Analyse indexing of the given Nominatim object')
42 from ..tools import admin
44 AdminFuncs._warm(args)
46 if args.check_database:
47 run_legacy_script('check_import_finished.php', nominatim_env=args)
49 if args.analyse_indexing:
50 conn = connect(args.config.get_libpq_dsn())
51 admin.analyse_indexing(conn, osm_id=args.osm_id, place_id=args.place_id)
60 if args.target == 'reverse':
61 params.append('--reverse-only')
62 if args.target == 'search':
63 params.append('--search-only')
64 return run_legacy_script(*params, nominatim_env=args)