Skip to content
Snippets Groups Projects
Commit 6939767a authored by Dmitry Shelepnev's avatar Dmitry Shelepnev
Browse files

Add sopds_util pg_optimize cmd for PostgreSQL Optimization

parent 886bd46c
No related branches found
No related tags found
No related merge requests found
from django.core.management.base import BaseCommand
from django.core.management import call_command
from django.db import transaction
from django.db import connection
from django.conf import settings as main_settings
from opds_catalog import opdsdb
......@@ -14,7 +15,7 @@ class Command(BaseCommand):
verbose = False
def add_arguments(self, parser):
parser.add_argument('command', action="store", nargs='*', help='Use [ clear | info | save_mygenres | load_mygenres | setconf | getconf ]')
parser.add_argument('command', action="store", nargs='*', help='Use [ clear | info | save_mygenres | load_mygenres | setconf | getconf | pg_optimize ]')
parser.add_argument('--verbose',action='store_true', dest='verbose', default=False, help='Set verbosity level for books collection scan.')
parser.add_argument('--nogenres',action='store_true', dest='nogenres', default=False, help='Not install genres fom fixtures.')
......@@ -40,6 +41,8 @@ class Command(BaseCommand):
elif action == "getconf":
self.confparam = options['command'][1] if len(options['command'])>1 else None
self.getconf(self.confparam)
elif action == "pg_optimize":
self.pg_optimize()
def clear(self):
with transaction.atomic():
......@@ -47,6 +50,7 @@ class Command(BaseCommand):
if not self.nogenres:
call_command('loaddata', 'genre.json', app_label='opds_catalog')
Counter.objects.update_known_counters()
opdsdb.pg_optimize(False)
def info(self):
Counter.objects.update_known_counters()
......@@ -78,5 +82,9 @@ class Command(BaseCommand):
else:
call_command('constance', 'list', app_label='opds_catalog')
def pg_optimize(self):
opdsdb.pg_optimize(True)
......@@ -42,6 +42,17 @@ unknown_genre=_(unknown_genre_en)
#
utfhigh = re.compile(u'[\U00010000-\U0010ffff]')
def pg_optimize(verbose=False):
""" TODO: Table optimizations for Postgre """
if connection.vendor != 'postgresql':
if verbose:
print('No PostgreSql connection backend detected...')
else:
cursor = connection.cursor()
cursor.execute('alter table opds_catalog_book SET ( fillfactor = 50)')
cursor.execute('VACUUM FULL opds_catalog_book')
print('PostgreSql tables internal structure optimized...')
def clear_all(verbose=False):
cursor = connection.cursor()
cursor.execute('delete from opds_catalog_bseries')
......
......@@ -28,7 +28,6 @@ from django.dispatch import receiver
# translation.activate(new_value)
# print(new_value)
def constance_update_all():
pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment