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
|
||||
container_name: postgres-sb-mirror
|
||||
shm_size: 1g
|
||||
user: 0:0
|
||||
# ports:
|
||||
# - 5432:5432
|
||||
volumes:
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -95,21 +95,26 @@ fn rocket() -> Rocket<Build> {
|
|||
let start = Instant::now();
|
||||
println!("Importing database...");
|
||||
// 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;");
|
||||
if result.is_err() {
|
||||
c.batch_execute("ROLLBACK;").unwrap();
|
||||
eprintln!("Failed to import database: {}", result.err().unwrap());
|
||||
return false;
|
||||
}
|
||||
println!("Imported database in {}ms", start.elapsed().as_millis());
|
||||
// Vacuum the database
|
||||
let result = c.batch_execute("VACUUM \"sponsorTimes\";");
|
||||
if result.is_err() {
|
||||
eprintln!("Failed to vacuum database: {}", result.err().unwrap());
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
}).await;
|
||||
|
||||
unsafe {
|
||||
LAST_UPDATE = Some(last_modified);
|
||||
if res {
|
||||
unsafe { LAST_UPDATE = Some(last_modified) };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue