From 9a70a2159543f1b2389e1d89b4dce41683ab5189 Mon Sep 17 00:00:00 2001 From: ThinkChaos Date: Fri, 9 Aug 2024 19:33:43 -0400 Subject: [PATCH] feat: mark SQLite custom functions as deterministic to allow caching --- beets/dbcore/db.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/beets/dbcore/db.py b/beets/dbcore/db.py index 7e8ff01c5a..92d73aa8fc 100755 --- a/beets/dbcore/db.py +++ b/beets/dbcore/db.py @@ -20,11 +20,12 @@ import os import re import sqlite3 +import sys import threading import time from abc import ABC from collections import defaultdict -from sqlite3 import Connection +from sqlite3 import Connection, sqlite_version_info from types import TracebackType from typing import ( Any, @@ -1143,9 +1144,14 @@ def bytelower(bytestring: Optional[AnyStr]) -> Optional[AnyStr]: return bytestring - conn.create_function("regexp", 2, regexp) - conn.create_function("unidecode", 1, unidecode) - conn.create_function("bytelower", 1, bytelower) + deterministic = {} + if sys.version_info >= (3, 8) and sqlite_version_info >= (3, 8, 3): + # Let sqlite make extra optimizations + deterministic["deterministic"] = True + + conn.create_function("regexp", 2, regexp, **deterministic) + conn.create_function("unidecode", 1, unidecode, **deterministic) + conn.create_function("bytelower", 1, bytelower, **deterministic) def _close(self): """Close the all connections to the underlying SQLite database