2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-12-22 19:31:35 +00:00

Mark variants as accessed on fetch

This commit is contained in:
asonix 2023-07-22 18:50:04 -05:00
parent b9e6d67d15
commit 47e13ec04e
3 changed files with 40 additions and 2 deletions

View file

@ -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?;

View file

@ -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,

View file

@ -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,