]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/clicmd/admin.py
convert admin --analyse-indexing to new indexing method
[nominatim.git] / nominatim / clicmd / admin.py
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Implementation of the 'admin' subcommand.
9 """
10 import logging
11
12 from nominatim.tools.exec_utils import run_legacy_script
13
14 # Do not repeat documentation of subcommand classes.
15 # pylint: disable=C0111
16 # Using non-top-level imports to avoid eventually unused imports.
17 # pylint: disable=E0012,C0415
18
19 LOG = logging.getLogger()
20
21 class AdminFuncs:
22     """\
23     Analyse and maintain the database.
24     """
25
26     @staticmethod
27     def add_args(parser):
28         group = parser.add_argument_group('Admin tasks')
29         objs = group.add_mutually_exclusive_group(required=True)
30         objs.add_argument('--warm', action='store_true',
31                           help='Warm database caches for search and reverse queries')
32         objs.add_argument('--check-database', action='store_true',
33                           help='Check that the database is complete and operational')
34         objs.add_argument('--migrate', action='store_true',
35                           help='Migrate the database to a new software version')
36         objs.add_argument('--analyse-indexing', action='store_true',
37                           help='Print performance analysis of the indexing process')
38         group = parser.add_argument_group('Arguments for cache warming')
39         group.add_argument('--search-only', action='store_const', dest='target',
40                            const='search',
41                            help="Only pre-warm tables for search queries")
42         group.add_argument('--reverse-only', action='store_const', dest='target',
43                            const='reverse',
44                            help="Only pre-warm tables for reverse queries")
45         group = parser.add_argument_group('Arguments for index anaysis')
46         mgroup = group.add_mutually_exclusive_group()
47         mgroup.add_argument('--osm-id', type=str,
48                             help='Analyse indexing of the given OSM object')
49         mgroup.add_argument('--place-id', type=int,
50                             help='Analyse indexing of the given Nominatim object')
51
52     @staticmethod
53     def run(args):
54         if args.warm:
55             return AdminFuncs._warm(args)
56
57         if args.check_database:
58             LOG.warning('Checking database')
59             from ..tools import check_database
60             return check_database.check_database(args.config)
61
62         if args.analyse_indexing:
63             LOG.warning('Analysing performance of indexing function')
64             from ..tools import admin
65             admin.analyse_indexing(args.config, osm_id=args.osm_id, place_id=args.place_id)
66             return 0
67
68         if args.migrate:
69             LOG.warning('Checking for necessary database migrations')
70             from ..tools import migration
71             return migration.migrate(args.config, args)
72
73         return 1
74
75
76     @staticmethod
77     def _warm(args):
78         LOG.warning('Warming database caches')
79         params = ['warm.php']
80         if args.target == 'reverse':
81             params.append('--reverse-only')
82         if args.target == 'search':
83             params.append('--search-only')
84         return run_legacy_script(*params, nominatim_env=args)