mirror of
https://github.com/TeamPiped/sponsorblock-mirror.git
synced 2024-08-14 23:57:05 +00:00
Rollback on transaction failure, and run postgres as root.
This commit is contained in:
parent
5e945d0914
commit
6608a9993a
2 changed files with 9 additions and 3 deletions
|
@ -15,6 +15,7 @@ services:
|
||||||
image: postgres:15-alpine
|
image: postgres:15-alpine
|
||||||
container_name: postgres-sb-mirror
|
container_name: postgres-sb-mirror
|
||||||
shm_size: 1g
|
shm_size: 1g
|
||||||
|
user: 0:0
|
||||||
# ports:
|
# ports:
|
||||||
# - 5432:5432
|
# - 5432:5432
|
||||||
volumes:
|
volumes:
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -95,21 +95,26 @@ fn rocket() -> Rocket<Build> {
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
println!("Importing database...");
|
println!("Importing database...");
|
||||||
// Execute a query of some kind
|
// Execute a query of some kind
|
||||||
db.run(move |c| {
|
let res = db.run(move |c| {
|
||||||
let result = c.batch_execute("BEGIN; DROP TABLE IF EXISTS \"sponsorTimesTemp\"; CREATE UNLOGGED TABLE \"sponsorTimesTemp\"(LIKE \"sponsorTimes\" INCLUDING defaults INCLUDING constraints INCLUDING indexes); COPY \"sponsorTimesTemp\" FROM '/mirror/sponsorTimes.csv' DELIMITER ',' CSV HEADER; DROP TABLE \"sponsorTimes\"; ALTER TABLE \"sponsorTimesTemp\" RENAME TO \"sponsorTimes\"; COMMIT;");
|
let result = c.batch_execute("BEGIN; DROP TABLE IF EXISTS \"sponsorTimesTemp\"; CREATE UNLOGGED TABLE \"sponsorTimesTemp\"(LIKE \"sponsorTimes\" INCLUDING defaults INCLUDING constraints INCLUDING indexes); COPY \"sponsorTimesTemp\" FROM '/mirror/sponsorTimes.csv' DELIMITER ',' CSV HEADER; DROP TABLE \"sponsorTimes\"; ALTER TABLE \"sponsorTimesTemp\" RENAME TO \"sponsorTimes\"; COMMIT;");
|
||||||
if result.is_err() {
|
if result.is_err() {
|
||||||
|
c.batch_execute("ROLLBACK;").unwrap();
|
||||||
eprintln!("Failed to import database: {}", result.err().unwrap());
|
eprintln!("Failed to import database: {}", result.err().unwrap());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
println!("Imported database in {}ms", start.elapsed().as_millis());
|
println!("Imported database in {}ms", start.elapsed().as_millis());
|
||||||
// Vacuum the database
|
// Vacuum the database
|
||||||
let result = c.batch_execute("VACUUM \"sponsorTimes\";");
|
let result = c.batch_execute("VACUUM \"sponsorTimes\";");
|
||||||
if result.is_err() {
|
if result.is_err() {
|
||||||
eprintln!("Failed to vacuum database: {}", result.err().unwrap());
|
eprintln!("Failed to vacuum database: {}", result.err().unwrap());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
true
|
||||||
}).await;
|
}).await;
|
||||||
|
|
||||||
unsafe {
|
if res {
|
||||||
LAST_UPDATE = Some(last_modified);
|
unsafe { LAST_UPDATE = Some(last_modified) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue