From feaa29a6404d696ecd19429291a83880347ed937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Thu, 22 Aug 2019 14:58:08 -0400 Subject: [PATCH] Continuing development. --- bazarr/database.py | 14 ++++++++++---- bazarr/get_episodes.py | 13 +++---------- bazarr/get_movies.py | 13 +++++++++++-- bazarr/list_subtitles.py | 1 - bazarr/scheduler.py | 4 ++-- 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/bazarr/database.py b/bazarr/database.py index c1f7ab2d9..bee060907 100644 --- a/bazarr/database.py +++ b/bazarr/database.py @@ -14,10 +14,6 @@ database = SqliteQueueDatabase( queue_max_size=256, # Max. # of pending writes that can accumulate. results_timeout=30.0) # Max. time to wait for query to be executed. -#database = SqliteDatabase(os.path.join(args.config_dir, 'db', 'bazarr.db'), pragmas={ -# 'journal_mode': 'wal', -# 'cache_size': -1024 * 8}) - @database.func('path_substitution') def path_substitution(path): @@ -174,6 +170,11 @@ class TableSettingsNotifier(BaseModel): def database_init(): database.connect() + database.pragma('wal_checkpoint', 'TRUNCATE') # Run a checkpoint and merge remaining wal-journal. + database.cache_size = -1024 # Number of KB of cache for wal-journal. + # Must be negative because positive means number of pages. + database.wal_autocheckpoint = 50 # Run an automatic checkpoint every 50 write transactions. + models_list = [TableShows, TableEpisodes, TableMovies, TableHistory, TableHistoryMovie, TableSettingsLanguages, TableSettingsNotifier, System] @@ -189,6 +190,11 @@ def database_init(): ).execute() +def wal_cleaning(): + database.pragma('wal_checkpoint', 'TRUNCATE') # Run a checkpoint and merge remaining wal-journal. + database.wal_autocheckpoint = 50 # Run an automatic checkpoint every 50 write transactions. + + @atexit.register def _stop_worker_threads(): database.close() diff --git a/bazarr/get_episodes.py b/bazarr/get_episodes.py index 12997151c..33ec6e1d1 100644 --- a/bazarr/get_episodes.py +++ b/bazarr/get_episodes.py @@ -4,13 +4,12 @@ import requests import logging import re from queueconfig import notifications -from database import TableShows, TableEpisodes +from database import TableShows, TableEpisodes, wal_cleaning from get_args import args from config import settings, url_sonarr from helper import path_replace -from list_subtitles import list_missing_subtitles, store_subtitles, series_full_scan_subtitles, \ - movies_full_scan_subtitles +from list_subtitles import list_missing_subtitles, store_subtitles, series_full_scan_subtitles from get_subtitle import episode_download_subtitles @@ -19,13 +18,7 @@ def update_all_episodes(): logging.info('BAZARR All existing episode subtitles indexed from disk.') list_missing_subtitles() logging.info('BAZARR All missing episode subtitles updated in database.') - - -def update_all_movies(): - movies_full_scan_subtitles() - logging.info('BAZARR All existing movie subtitles indexed from disk.') - list_missing_subtitles() - logging.info('BAZARR All missing movie subtitles updated in database.') + wal_cleaning() def sync_episodes(): diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py index 82cb8b68f..87233df00 100644 --- a/bazarr/get_movies.py +++ b/bazarr/get_movies.py @@ -8,9 +8,18 @@ from queueconfig import notifications from get_args import args from config import settings, url_radarr from helper import path_replace_movie -from list_subtitles import store_subtitles_movie, list_missing_subtitles_movies +from list_subtitles import store_subtitles_movie, list_missing_subtitles_movies, movies_full_scan_subtitles + from get_subtitle import movies_download_subtitles -from database import TableMovies +from database import TableMovies, wal_cleaning + + +def update_all_movies(): + movies_full_scan_subtitles() + logging.info('BAZARR All existing movie subtitles indexed from disk.') + list_missing_subtitles_movies() + logging.info('BAZARR All missing movie subtitles updated in database.') + wal_cleaning() def update_movies(): diff --git a/bazarr/list_subtitles.py b/bazarr/list_subtitles.py index f691ac737..4d4bc28d7 100644 --- a/bazarr/list_subtitles.py +++ b/bazarr/list_subtitles.py @@ -32,7 +32,6 @@ def store_subtitles(file): logging.debug('BAZARR started subtitles indexing for this file: ' + file) actual_subtitles = [] if os.path.exists(file): - # notifications.write(msg='Analyzing this file for subtitles: ' + file, queue='list_subtitles') if settings.general.getboolean('use_embedded_subs'): logging.debug("BAZARR is trying to index embedded subtitles.") try: diff --git a/bazarr/scheduler.py b/bazarr/scheduler.py index bb2bff681..cf6ea1f02 100644 --- a/bazarr/scheduler.py +++ b/bazarr/scheduler.py @@ -1,7 +1,7 @@ # coding=utf-8 -from get_episodes import sync_episodes, update_all_episodes, update_all_movies -from get_movies import update_movies +from get_episodes import sync_episodes, update_all_episodes +from get_movies import update_movies, update_all_movies from get_series import update_series from config import settings from get_subtitle import wanted_search_missing_subtitles, upgrade_subtitles