2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-12-22 11:21:24 +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, queue::queue_generate,
repo::{ repo::{
sled::SledRepo, Alias, DeleteToken, FullRepo, HashRepo, IdentifierRepo, QueueRepo, Repo, sled::SledRepo, Alias, DeleteToken, FullRepo, HashRepo, IdentifierRepo, QueueRepo, Repo,
SettingsRepo, UploadId, UploadResult, SettingsRepo, UploadId, UploadResult, VariantAccessRepo,
}, },
serde_str::Serde, serde_str::Serde,
store::{ 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 let identifier = repo
.variant_identifier::<S::Identifier>(hash, thumbnail_path.to_string_lossy().to_string()) .variant_identifier::<S::Identifier>(hash, thumbnail_string)
.await? .await?
.ok_or(UploadError::MissingAlias)?; .ok_or(UploadError::MissingAlias)?;
@ -706,6 +713,10 @@ async fn process<R: FullRepo, S: Store + 'static>(
(hash, alias, true) (hash, alias, true)
}; };
if !config.server.read_only {
repo.accessed(hash.clone(), path_string.clone()).await?;
}
let identifier_opt = repo let identifier_opt = repo
.variant_identifier::<S::Identifier>(hash.clone(), path_string) .variant_identifier::<S::Identifier>(hash.clone(), path_string)
.await?; .await?;
@ -819,6 +830,10 @@ async fn process_head<R: FullRepo, S: Store + 'static>(
return Ok(HttpResponse::NotFound().finish()); return Ok(HttpResponse::NotFound().finish());
}; };
if !config.server.read_only {
repo.accessed(hash.clone(), path_string.clone()).await?;
}
let identifier_opt = repo let identifier_opt = repo
.variant_identifier::<S::Identifier>(hash.clone(), path_string) .variant_identifier::<S::Identifier>(hash.clone(), path_string)
.await?; .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 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( async fn older_variants(
&self, &self,
timestamp: time::OffsetDateTime, timestamp: time::OffsetDateTime,
@ -207,6 +210,14 @@ where
T::accessed(self, hash, variant).await 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( async fn older_variants(
&self, &self,
timestamp: time::OffsetDateTime, timestamp: time::OffsetDateTime,

View file

@ -354,6 +354,18 @@ impl VariantAccessRepo for SledRepo {
.map_err(RepoError::from) .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( async fn older_variants(
&self, &self,
timestamp: time::OffsetDateTime, timestamp: time::OffsetDateTime,