Skip to content

Commit

Permalink
feat: mark SQLite custom functions as deterministic to allow caching
Browse files Browse the repository at this point in the history
  • Loading branch information
ThinkChaos committed Aug 10, 2024
1 parent 94708de commit 9a70a21
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions beets/dbcore/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9a70a21

Please sign in to comment.