Skip to content

Commit ebabfa5

Browse files
committed
only use media_uniq_path_idx on tube* that need it, more strict otherwise
1 parent afbe0c5 commit ebabfa5

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

library/mediadb/db_media.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,18 @@ def create(args):
2828
);
2929
"""
3030
)
31-
try:
32-
args.db.execute("CREATE UNIQUE INDEX IF NOT EXISTS media_uniq_path_idx ON media (playlists_id, path);")
33-
except sqlite3.IntegrityError:
34-
dedupe_rows(args, "media", ["rowid"], ["playlists_id", "path"])
35-
args.db.execute("CREATE UNIQUE INDEX IF NOT EXISTS media_uniq_path_idx ON media (playlists_id, path);")
31+
if args.action in ("tube-add", "gallery-add", "web-add", "site-add"):
32+
try:
33+
args.db.execute("CREATE UNIQUE INDEX IF NOT EXISTS media_uniq_path_idx ON media (playlists_id, path);")
34+
except sqlite3.IntegrityError:
35+
dedupe_rows(args, "media", ["rowid"], ["playlists_id", "path"])
36+
args.db.execute("CREATE UNIQUE INDEX IF NOT EXISTS media_uniq_path_idx ON media (playlists_id, path);")
37+
else:
38+
try:
39+
args.db.execute("CREATE UNIQUE INDEX IF NOT EXISTS idx_media_path ON media (path);")
40+
except sqlite3.IntegrityError:
41+
dedupe_rows(args, "media", ["rowid"], ["path"])
42+
args.db.execute("CREATE UNIQUE INDEX IF NOT EXISTS idx_media_path ON media (path);")
3643

3744

3845
def exists(args, path) -> bool:

library/utils/arggroups.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,12 @@ def extractor(parent_parser):
10781078
help="Convert UTF-8 IRIs (RFC 3987) to ASCII percent-encoded URLs (RFC 1738)",
10791079
)
10801080
parser.add_argument(
1081-
"--no-extract", "--skip-extract", "--insert-only", action="store_true", help="Insert paths into media table"
1081+
"--no-extract",
1082+
"--skip-extract",
1083+
"--insert-only",
1084+
"-n",
1085+
action="store_true",
1086+
help="Insert paths into media table",
10821087
) # TODO: move to its own subcommand
10831088
parser.add_argument(
10841089
"--no-extract-playlists",

tests/playback/test_links_open.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_links_open(mock_souffle):
1414
media = mock_souffle.call_args[0][1]
1515
assert len(media) == 3
1616
assert media == [
17-
{"path": "https://site0", "category": "p1"},
18-
{"path": "https://site1", "category": "p1"},
19-
{"path": "https://site2", "category": "p1"},
17+
{"path": "https://site0", "hostname": "site0", "category": "p1"},
18+
{"path": "https://site1", "hostname": "site1", "category": "p1"},
19+
{"path": "https://site2", "hostname": "site2", "category": "p1"},
2020
]

0 commit comments

Comments
 (0)