Revisão | cd03cc05fb9118749950d6374aae11ccc12fea61 (tree) |
---|---|
Hora | 2017-12-26 20:53:57 |
Autor | Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@fast...> |
Commiter | Jaime Marquínez Ferrándiz |
Reduce the number of transactions
@@ -63,27 +63,27 @@ | ||
63 | 63 | db.execute('DELETE FROM playlistsong') |
64 | 64 | |
65 | 65 | for query in config['queries'].get(list): |
66 | - self.info('Processing query: "{0}"', query) | |
67 | - items = lib.items(query) | |
68 | - for item in items: | |
69 | - self.add_item(lib, db, item) | |
70 | 66 | with db: |
67 | + self.info('Processing query: "{0}"', query) | |
68 | + items = lib.items(query) | |
69 | + for item in items: | |
70 | + self.add_item(lib, db, item) | |
71 | 71 | db.execute('INSERT INTO query (query) VALUES (?)', (query,)) |
72 | 72 | query_id = db.execute('SELECT idQuery FROM query WHERE query=?', (query,)).fetchone()[0] |
73 | 73 | db.executemany('INSERT INTO querysong VALUES (?, ?)', [(query_id, item['id']) for item in items]) |
74 | 74 | |
75 | 75 | for playlist in config['playlists'].get(list): |
76 | - self.info('Processing playlist: "{0}"', playlist) | |
77 | - playlist_file = os.path.expanduser(playlist) | |
78 | - with open(playlist_file, 'rt') as f: | |
79 | - paths = [line for line in (line.strip() for line in f) if line and not line.startswith('#')] | |
80 | - items = [] | |
81 | - for song_path in paths: | |
82 | - query, q_sort = parse_query_parts(['path:' + song_path], Item) | |
83 | - item = list(lib.items(OrQuery(query)))[0] | |
84 | - self.add_item(lib, db, item) | |
85 | - items.append(item) | |
86 | 76 | with db: |
77 | + self.info('Processing playlist: "{0}"', playlist) | |
78 | + playlist_file = os.path.expanduser(playlist) | |
79 | + with open(playlist_file, 'rt') as f: | |
80 | + paths = [line for line in (line.strip() for line in f) if line and not line.startswith('#')] | |
81 | + items = [] | |
82 | + for song_path in paths: | |
83 | + query, q_sort = parse_query_parts(['path:' + song_path], Item) | |
84 | + item = list(lib.items(OrQuery(query)))[0] | |
85 | + self.add_item(lib, db, item) | |
86 | + items.append(item) | |
87 | 87 | db.execute( |
88 | 88 | 'INSERT INTO playlist (playlist) VALUES (?)', |
89 | 89 | (playlist,)) |
@@ -146,5 +146,4 @@ | ||
146 | 146 | if IS_PY3 and isinstance(copy_path, bytes): |
147 | 147 | copy_path = copy_path.decode() |
148 | 148 | if not db.execute('SELECT * FROM song WHERE idSong=?', (item_id,)).fetchall(): |
149 | - with db: | |
150 | - db.execute('INSERT INTO song (idSong, filename) VALUES (?,?)', (item_id, copy_path)) | |
149 | + db.execute('INSERT INTO song (idSong, filename) VALUES (?,?)', (item_id, copy_path)) |