mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-11-09 22:14:59 +00:00
Mark variants as accessed on fetch
This commit is contained in:
parent
b9e6d67d15
commit
47e13ec04e
3 changed files with 40 additions and 2 deletions
19
src/lib.rs
19
src/lib.rs
|
@ -69,7 +69,7 @@ use self::{
|
|||
queue::queue_generate,
|
||||
repo::{
|
||||
sled::SledRepo, Alias, DeleteToken, FullRepo, HashRepo, IdentifierRepo, QueueRepo, Repo,
|
||||
SettingsRepo, UploadId, UploadResult,
|
||||
SettingsRepo, UploadId, UploadResult, VariantAccessRepo,
|
||||
},
|
||||
serde_str::Serde,
|
||||
store::{
|
||||
|
@ -647,8 +647,15 @@ async fn process_details<R: FullRepo, S: Store>(
|
|||
})));
|
||||
};
|
||||
|
||||
let thumbnail_string = thumbnail_path.to_string_lossy().to_string();
|
||||
|
||||
if !config.server.read_only {
|
||||
repo.accessed(hash.clone(), thumbnail_string.clone())
|
||||
.await?;
|
||||
}
|
||||
|
||||
let identifier = repo
|
||||
.variant_identifier::<S::Identifier>(hash, thumbnail_path.to_string_lossy().to_string())
|
||||
.variant_identifier::<S::Identifier>(hash, thumbnail_string)
|
||||
.await?
|
||||
.ok_or(UploadError::MissingAlias)?;
|
||||
|
||||
|
@ -706,6 +713,10 @@ async fn process<R: FullRepo, S: Store + 'static>(
|
|||
(hash, alias, true)
|
||||
};
|
||||
|
||||
if !config.server.read_only {
|
||||
repo.accessed(hash.clone(), path_string.clone()).await?;
|
||||
}
|
||||
|
||||
let identifier_opt = repo
|
||||
.variant_identifier::<S::Identifier>(hash.clone(), path_string)
|
||||
.await?;
|
||||
|
@ -819,6 +830,10 @@ async fn process_head<R: FullRepo, S: Store + 'static>(
|
|||
return Ok(HttpResponse::NotFound().finish());
|
||||
};
|
||||
|
||||
if !config.server.read_only {
|
||||
repo.accessed(hash.clone(), path_string.clone()).await?;
|
||||
}
|
||||
|
||||
let identifier_opt = repo
|
||||
.variant_identifier::<S::Identifier>(hash.clone(), path_string)
|
||||
.await?;
|
||||
|
|
11
src/repo.rs
11
src/repo.rs
|
@ -188,6 +188,9 @@ pub(crate) trait VariantAccessRepo: BaseRepo {
|
|||
|
||||
async fn accessed(&self, hash: Self::Bytes, variant: String) -> Result<(), RepoError>;
|
||||
|
||||
async fn contains_variant(&self, hash: Self::Bytes, variant: String)
|
||||
-> Result<bool, RepoError>;
|
||||
|
||||
async fn older_variants(
|
||||
&self,
|
||||
timestamp: time::OffsetDateTime,
|
||||
|
@ -207,6 +210,14 @@ where
|
|||
T::accessed(self, hash, variant).await
|
||||
}
|
||||
|
||||
async fn contains_variant(
|
||||
&self,
|
||||
hash: Self::Bytes,
|
||||
variant: String,
|
||||
) -> Result<bool, RepoError> {
|
||||
T::contains_variant(self, hash, variant).await
|
||||
}
|
||||
|
||||
async fn older_variants(
|
||||
&self,
|
||||
timestamp: time::OffsetDateTime,
|
||||
|
|
|
@ -354,6 +354,18 @@ impl VariantAccessRepo for SledRepo {
|
|||
.map_err(RepoError::from)
|
||||
}
|
||||
|
||||
async fn contains_variant(
|
||||
&self,
|
||||
hash: Self::Bytes,
|
||||
variant: String,
|
||||
) -> Result<bool, RepoError> {
|
||||
let key = variant_access_key(&hash, &variant);
|
||||
|
||||
let timestamp = b!(self.variant_access, variant_access.get(key));
|
||||
|
||||
Ok(timestamp.is_some())
|
||||
}
|
||||
|
||||
async fn older_variants(
|
||||
&self,
|
||||
timestamp: time::OffsetDateTime,
|
||||
|
|
Loading…
Reference in a new issue