Skip to content

Commit d767ab3

Browse files
committed
optimized file update query. version bump
1 parent 0a6f92f commit d767ab3

3 files changed

Lines changed: 41 additions & 41 deletions

File tree

Cargo.lock

Lines changed: 31 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "flac-reencoder"
3-
version = "0.2.6"
3+
version = "0.2.7"
44
edition = "2024"
55
repository = "https://github.com/justjakka/reencoder/"
66
license = "BSD-3-Clause"

src/db.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use std::{
99
use crate::flac::{CURRENT_VENDOR, get_vendor};
1010

1111
const TABLE_CREATE: &str = "CREATE TABLE IF NOT EXISTS flacs (path TEXT PRIMARY KEY UNIQUE, toencode BOOLEAN NOT NULL, modtime INTEGER)";
12-
const ADD_NEW_ITEM: &str = "INSERT INTO flacs (path, toencode, modtime) VALUES (?1, ?2, ?3)";
13-
const REPLACE_ITEM: &str = "REPLACE INTO flacs (path, toencode, modtime) VALUES (?1, ?2, ?3)";
14-
const TOENCODE_QUERY: &str = "SELECT path FROM flacs WHERE toencode";
12+
const ADD_ITEM: &str = "INSERT INTO flacs (path, toencode, modtime) VALUES (?1, ?2, ?3)";
13+
const UPDATE_ITEM: &str = "UPDATE flacs SET toencode = ?2, modtime = ?3 WHERE path = ?1";
14+
const TOENCODE_PATHS: &str = "SELECT path FROM flacs WHERE toencode";
1515
const TOENCODE_NUMBER: &str = "SELECT COUNT(*) from flacs WHERE toencode";
1616
const CHECK_FILE: &str = "SELECT exists(SELECT 1 FROM flacs WHERE path = ?1)";
1717
const FETCH_FILES: &str = "SELECT path FROM flacs";
@@ -60,7 +60,7 @@ impl Database for Connection {
6060
.as_secs();
6161

6262
self.execute(
63-
ADD_NEW_ITEM,
63+
ADD_ITEM,
6464
params![filename.as_ref().to_str().unwrap(), toencode, modtime],
6565
)?;
6666

@@ -76,7 +76,7 @@ impl Database for Connection {
7676
.as_secs();
7777

7878
self.execute(
79-
REPLACE_ITEM,
79+
UPDATE_ITEM,
8080
params![filename.as_ref().to_str().unwrap(), false, modtime],
8181
)?;
8282

@@ -116,7 +116,7 @@ impl Database for Connection {
116116
}
117117

118118
fn get_toencode_files(&self) -> Result<Vec<PathBuf>, rusqlite::Error> {
119-
let mut stmt = self.prepare(TOENCODE_QUERY)?;
119+
let mut stmt = self.prepare(TOENCODE_PATHS)?;
120120
let mut rows = stmt.query(())?;
121121
let mut files: Vec<PathBuf> = Vec::new();
122122
while let Ok(Some(row)) = rows.next() {
@@ -168,7 +168,7 @@ mod tests {
168168
for file in filenames {
169169
conn.insert_file(&file.to_string()).unwrap();
170170
}
171-
let mut stmt = conn.prepare(TOENCODE_QUERY).unwrap();
171+
let mut stmt = conn.prepare(TOENCODE_PATHS).unwrap();
172172
let mut returned = stmt.query(()).unwrap();
173173

174174
while let Ok(Some(_)) = returned.next() {
@@ -193,7 +193,7 @@ mod tests {
193193
}
194194

195195
conn.execute(
196-
REPLACE_ITEM,
196+
UPDATE_ITEM,
197197
params![
198198
Path::new("./samples/16bit.flac")
199199
.canonicalize()
@@ -215,7 +215,7 @@ mod tests {
215215
)
216216
.unwrap();
217217

218-
let mut stmt = conn.prepare(TOENCODE_QUERY).unwrap();
218+
let mut stmt = conn.prepare(TOENCODE_PATHS).unwrap();
219219
let mut returned = stmt.query(()).unwrap();
220220
let mut counter = 0;
221221
while let Ok(Some(_)) = returned.next() {

0 commit comments

Comments
 (0)