1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-09 19:52:16 +00:00

Properly close database connections when they're not in use

Watcher
Closes #253
This commit is contained in:
Alban Féron 2023-04-21 17:04:44 +02:00
parent 32a74706c2
commit abe0b79968
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165

View File

@ -14,7 +14,7 @@ from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler from watchdog.events import PatternMatchingEventHandler
from . import covers from . import covers
from .db import Folder from .db import Folder, open_connection, close_connection
from .scanner import Scanner from .scanner import Scanner
OP_SCAN = 1 OP_SCAN = 1
@ -45,16 +45,9 @@ class SupysonicWatcherEventHandler(PatternMatchingEventHandler):
logger.debug("File created: '%s'", event.src_path) logger.debug("File created: '%s'", event.src_path)
op = OP_SCAN | FLAG_CREATE op = OP_SCAN | FLAG_CREATE
if not covers.is_valid_cover(event.src_path): if covers.is_valid_cover(event.src_path):
self.queue.put(event.src_path, op) op |= FLAG_COVER
self.queue.put(event.src_path, op)
dirname = os.path.dirname(event.src_path)
try:
Folder.get(path=dirname)
except Folder.DoesNotExist:
self.queue.put(dirname, op | FLAG_COVER)
else:
self.queue.put(event.src_path, op | FLAG_COVER)
def on_deleted(self, event): def on_deleted(self, event):
logger.debug("File deleted: '%s'", event.src_path) logger.debug("File deleted: '%s'", event.src_path)
@ -154,6 +147,7 @@ class ScannerProcessingQueue(Thread):
continue continue
logger.debug("Instantiating scanner") logger.debug("Instantiating scanner")
open_connection()
scanner = Scanner() scanner = Scanner()
item = self.__next_item() item = self.__next_item()
@ -166,6 +160,7 @@ class ScannerProcessingQueue(Thread):
item = self.__next_item() item = self.__next_item()
scanner.prune() scanner.prune()
close_connection()
logger.debug("Freeing scanner") logger.debug("Freeing scanner")
def __process_regular_item(self, scanner, item): def __process_regular_item(self, scanner, item):