Skip to content

Commit

Permalink
Keep created and mtime timestamps for file versions separately
Browse files Browse the repository at this point in the history
  • Loading branch information
jendakol committed Dec 10, 2018
1 parent d816571 commit bdec37a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions resources/db-scheme.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ CREATE TABLE IF NOT EXISTS `DBNAME`.`files_versions` (
`id` bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`file_id` bigint(20) NOT NULL,
`created` datetime(3) NOT NULL,
`mtime` datetime(3) NOT NULL,
`size` int(11) NOT NULL,
`hash` char(64) NOT NULL,
`storage_name` char(64) NOT NULL,
Expand Down
13 changes: 8 additions & 5 deletions src/dao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ impl Dao {
let stopwatch = Stopwatch::start_new();

let r = self.pool.prep_exec(
format!("insert into `{}`.files_versions (file_id, created, size, hash, storage_name) values (:file_id, :created, :size, :hash, :storage_name)", self.db_name),
format!("insert into `{}`.files_versions (file_id, created, mtime, size, hash, storage_name) values (:file_id, :created, :mtime, :size, :hash, :storage_name)", self.db_name),
params! {"file_id" => file.id,
"created" => &new_file_version.created,
"mtime" => &new_file_version.mtime,
"size" => &new_file_version.size,
"hash" => &new_file_version.hash,
"storage_name" => &new_file_version.storage_name
Expand Down Expand Up @@ -143,7 +144,7 @@ impl Dao {
let stopwatch = Stopwatch::start_new();

let result = self.pool.prep_exec(
format!("select files.id, device_id, original_name, files_versions.id, size, hash, created, storage_name from `{}`.files join `{}`.files_versions on `{}`.files_versions.file_id = `{}`.files.id where identity_hash=:identity_hash",
format!("select files.id, device_id, original_name, files_versions.id, size, hash, created, mtime, storage_name from `{}`.files join `{}`.files_versions on `{}`.files_versions.file_id = `{}`.files.id where identity_hash=:identity_hash",
self.db_name, self.db_name, self.db_name, self.db_name),
params! { "identity_hash" => identity_hash}
)?;
Expand All @@ -152,7 +153,7 @@ impl Dao {

// TODO optimize
let file_with_versions = result.map(|x| x.unwrap()).map(|row| {
let (id, device_id, original_name, versionid, size, hash, created, storage_name) = mysql::from_row(row);
let (id, device_id, original_name, versionid, size, hash, created, mtime, storage_name) = mysql::from_row(row);

(
(id, device_id, original_name),
Expand All @@ -161,6 +162,7 @@ impl Dao {
size,
hash,
created,
mtime,
storage_name
}
)
Expand Down Expand Up @@ -244,13 +246,13 @@ impl Dao {
let stopwatch = Stopwatch::start_new();

self.pool.prep_exec(
format!("select files.id, device_id, original_name, files_versions.id, size, hash, created, storage_name from `{}`.files join `{}`.files_versions on `{}`.files_versions.file_id = `{}`.files.id where account_id=:account_id and device_id=:device_id",
format!("select files.id, device_id, original_name, files_versions.id, size, hash, created, mtime, storage_name from `{}`.files join `{}`.files_versions on `{}`.files_versions.file_id = `{}`.files.id where account_id=:account_id and device_id=:device_id",
self.db_name, self.db_name, self.db_name, self.db_name), params! { "device_id" => device_id, "account_id" => account_id}
).and_then(|result| {
self.report_timer("list_files", stopwatch);

let files: Vec<File> = result.map(|x| x.unwrap()).map(|row| {
let (id, device_id, original_name, versionid, size, hash, created, storage_name) = mysql::from_row(row);
let (id, device_id, original_name, versionid, size, hash, created, mtime, storage_name) = mysql::from_row(row);

(
(id, device_id, original_name),
Expand All @@ -259,6 +261,7 @@ impl Dao {
size,
hash,
created,
mtime,
storage_name
}
)
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ pub fn save(logger: &Logger, statsd_client: StatsdClient, repo: &Repo, dao: &Dao
version: 0, // cannot know now, will be filled in after DB insertion
size,
hash,
created: uploaded_file.mtime,
created: time_stamp,
mtime: uploaded_file.mtime,
storage_name
};

Expand Down
1 change: 1 addition & 0 deletions src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct FileVersion {
pub size: u64,
pub hash: String,
pub created: NaiveDateTime,
pub mtime: NaiveDateTime,
pub storage_name: String
}

Expand Down

0 comments on commit bdec37a

Please sign in to comment.