Skip to content

Commit

Permalink
Using u64 as file/file version ID
Browse files Browse the repository at this point in the history
  • Loading branch information
jendakol committed Oct 7, 2018
1 parent 43b321d commit e4cf88f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/dao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl Dao {
}
}

pub fn get_hash_size_and_storage_name(&self, version_id: u32) -> mysql::error::Result<Option<(String, u64, String)>> {
pub fn get_hash_size_and_storage_name(&self, version_id: u64) -> mysql::error::Result<Option<(String, u64, String)>> {
let stopwatch = Stopwatch::start_new();

self.pool.prep_exec(format!("select hash, size, storage_name from `{}`.files_versions where id=:version_id", self.db_name),
Expand All @@ -224,7 +224,7 @@ impl Dao {
})
}

pub fn get_storage_names(&self, device_id: &str, file_id: u32) -> mysql::error::Result<Vec<String>> {
pub fn get_storage_names(&self, device_id: &str, file_id: u64) -> mysql::error::Result<Vec<String>> {
let stopwatch = Stopwatch::start_new();

self.pool.prep_exec(format!("select storage_name from `{}`.files_versions join `{}`.files on `{}`.files_versions.file_id=`{}`.files.id where `{}`.files.id=:file_id and `{}`.files.device_id=:device_id", self.db_name, self.db_name, self.db_name, self.db_name, self.db_name, self.db_name),
Expand Down Expand Up @@ -283,7 +283,7 @@ impl Dao {
})
}

pub fn remove_file_version(&self, version_id: u32) -> mysql::error::Result<Option<String>> {
pub fn remove_file_version(&self, version_id: u64) -> mysql::error::Result<Option<String>> {
debug!(self.logger, "Deleting file version with"; "id" => version_id);

self.get_hash_size_and_storage_name(version_id)
Expand All @@ -302,7 +302,7 @@ impl Dao {
})
}

pub fn remove_file(&self, device_id: &str, file_id: u32) -> Result<Option<Vec<String>>, Error> {
pub fn remove_file(&self, device_id: &str, file_id: u64) -> Result<Option<Vec<String>>, Error> {
debug!(self.logger, "Deleting file versions"; "file_id" => file_id, "device_id" => device_id);

self.get_storage_names(device_id, file_id)
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ pub fn save(logger: &Logger, statsd_client: StatsdClient, repo: &Repo, dao: &Dao
})
}

pub fn load(logger: Logger, repo: &Repo, dao: &Dao, version_id: u32) -> Result<Option<(String, u64, Box<Read>)>, Error> {
pub fn load(logger: Logger, repo: &Repo, dao: &Dao, version_id: u64) -> Result<Option<(String, u64, Box<Read>)>, Error> {
dao.get_hash_size_and_storage_name(version_id)
.map(|n| {
n.map(|(hash, size, storage_name)| {
Expand Down Expand Up @@ -287,7 +287,7 @@ pub fn list_devices(dao: &Dao, account_id: &str) -> Result<ListDevicesResult, Er
.map_err(Error::from)
}

pub fn remove_file_version(repo: &Repo, dao: &Dao, version_id: u32) -> Result<RemoveFileVersionResult, Error> {
pub fn remove_file_version(repo: &Repo, dao: &Dao, version_id: u64) -> Result<RemoveFileVersionResult, Error> {
dao.remove_file_version(version_id)
.map_err(Error::from)
.map(|opt| opt.map(|sn| repo.repo.rm(&sn).map_err(Error::from)))
Expand All @@ -298,7 +298,7 @@ pub fn remove_file_version(repo: &Repo, dao: &Dao, version_id: u32) -> Result<Re
})
}

pub fn remove_file(repo: &Repo, dao: &Dao, device_id: &str, file_id: u32) -> Result<RemoveFileResult, Error> {
pub fn remove_file(repo: &Repo, dao: &Dao, device_id: &str, file_id: u64) -> Result<RemoveFileResult, Error> {
dao.remove_file(device_id, file_id)
.map(|opt| match opt {
Some(storage_names) => {
Expand Down
6 changes: 3 additions & 3 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ struct UploadMetadata {

#[derive(FromForm)]
struct DownloadMetadata {
file_version_id: u32,
file_version_id: u64,
}

#[derive(FromForm)]
struct RemoveFileMetadata {
file_id: u32,
file_id: u64,
}

#[derive(FromForm)]
Expand All @@ -41,7 +41,7 @@ struct ListFilesMetadata {

#[derive(FromForm)]
struct RemoveFileVersionMetadata {
file_version_id: u32,
file_version_id: u64,
}

#[derive(FromForm)]
Expand Down

0 comments on commit e4cf88f

Please sign in to comment.