Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(processing): 批量选择视频使用单参数集合查询

zouyonghe1c040f0c9d63
diff --git a/src/peach/library_processing.py b/src/peach/library_processing.py
index 621ac688b..30e359e01 100644
--- a/src/peach/library_processing.py
+++ b/src/peach/library_processing.py
@@ -2215,10 +2215,10 @@ def _asset_selection(db_path, asset_ids):
type(value) is not int or value <= 0 for value in asset_ids):
raise ValueError('请选择有效的视频项目')
chosen = list(dict.fromkeys(asset_ids))
- marks = ','.join('?' * len(chosen))
with closing(sqlite3.connect(db_path, timeout=30)) as connection:
found = {row[0] for row in connection.execute(
- f"SELECT id FROM asset WHERE id IN ({marks}) AND medium='video' AND disposal IS NULL", chosen)}
+ "SELECT id FROM asset WHERE id IN (SELECT value FROM json_each(?)) "
+ "AND medium='video' AND disposal IS NULL", (json.dumps(chosen),))}
if found != set(chosen):
raise ValueError('所选视频已不存在或已移入回收站,请刷新后重试')
return chosen
diff --git a/tests/test_metadata_library.py b/tests/test_metadata_library.py
index bf98b7d4e..796dcbade 100644
--- a/tests/test_metadata_library.py
+++ b/tests/test_metadata_library.py
@@ -3516,6 +3516,19 @@ class LibraryPreviewCompletionTests(unittest.TestCase):
self.assertEqual(retried['issue_count'], 0)
self.assertEqual(retried['retryable_asset_ids'], [])
+ def test_selected_assets_fit_the_connection_parameter_limit(self):
+ from peach.library_processing import _asset_selection
+ connect = sqlite3.connect
+ def limited_connection(*args, **kwargs):
+ connection = connect(*args, **kwargs)
+ connection.setlimit(sqlite3.SQLITE_LIMIT_VARIABLE_NUMBER, 1)
+ return connection
+ with patch('peach.library_processing.sqlite3.connect', side_effect=limited_connection):
+ self.assertEqual(_asset_selection(self.db, [2, 1, 2]), [2, 1])
+ for invalid in (3, 4, 99):
+ with self.subTest(invalid=invalid), self.assertRaises(ValueError):
+ _asset_selection(self.db, [2, 1, invalid])
+
def test_selected_assets_require_active_videos(self):
for selection in ([], [True], [0], [-1], ['1'], '1', [99], [3], [4]):
with self.subTest(selection=selection), self.assertRaises(ValueError), \