Compare commits
1 Commits
5b670ed775
...
779b68f053
Author | SHA1 | Date | |
---|---|---|---|
|
779b68f053 |
@ -9,7 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
## [0.2.0] - 2024-09-14
|
## [0.2.0] - 2024-09-14
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- add cache get
|
|
||||||
- send out wait
|
- send out wait
|
||||||
- add cache
|
- add cache
|
||||||
- add settings config
|
- add settings config
|
||||||
|
@ -52,37 +52,7 @@ impl Cache {
|
|||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(cache_duration) = self.app.config.settings.cache.duration.get_duration() {
|
let file = tokio::fs::read(location).await?;
|
||||||
let metadata = tokio::fs::metadata(&location).await?;
|
|
||||||
|
|
||||||
if let Ok(file_modified_last) = metadata
|
|
||||||
.modified()
|
|
||||||
.context("failed to get modified date")
|
|
||||||
.inspect_err(|e| {
|
|
||||||
tracing::warn!(
|
|
||||||
"could not get valid metadata from file, cache will be reused: {}",
|
|
||||||
e
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.and_then(|m| {
|
|
||||||
m.elapsed()
|
|
||||||
.context("failed to get elapsed from file")
|
|
||||||
.inspect_err(|e| tracing::warn!("failed to get elapsed from system: {}", e))
|
|
||||||
})
|
|
||||||
{
|
|
||||||
tracing::trace!(
|
|
||||||
cache = file_modified_last.as_secs(),
|
|
||||||
expiry = cache_duration.as_secs(),
|
|
||||||
"checking if cache is valid"
|
|
||||||
);
|
|
||||||
if file_modified_last > cache_duration {
|
|
||||||
tracing::debug!("cache has expired");
|
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let file = tokio::fs::read(&location).await?;
|
|
||||||
if file.is_empty() {
|
if file.is_empty() {
|
||||||
tracing::debug!("cache file appears to be empty");
|
tracing::debug!("cache file appears to be empty");
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
@ -117,7 +87,7 @@ pub trait CacheConfig {
|
|||||||
|
|
||||||
impl CacheConfig for Config {
|
impl CacheConfig for Config {
|
||||||
fn get_cache_location(&self) -> anyhow::Result<PathBuf> {
|
fn get_cache_location(&self) -> anyhow::Result<PathBuf> {
|
||||||
Ok(self.settings.cache.location.clone().into())
|
Ok(self.settings.cache.location.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_cache_file_location(&self) -> anyhow::Result<PathBuf> {
|
fn get_cache_file_location(&self) -> anyhow::Result<PathBuf> {
|
||||||
|
@ -27,7 +27,7 @@ impl RootCommand {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for repo in &repositories {
|
for repo in &repositories {
|
||||||
//tracing::info!("repo: {}", repo.to_rel_path().display());
|
tracing::info!("repo: {}", repo.to_rel_path().display());
|
||||||
}
|
}
|
||||||
|
|
||||||
tracing::info!("amount of repos fetched {}", repositories.len());
|
tracing::info!("amount of repos fetched {}", repositories.len());
|
||||||
|
@ -18,76 +18,17 @@ pub struct Settings {
|
|||||||
pub cache: Cache,
|
pub cache: Cache,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Serialize, Deserialize, PartialEq)]
|
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||||
pub struct Cache {
|
pub struct Cache {
|
||||||
#[serde(default)]
|
pub location: PathBuf,
|
||||||
pub location: CacheLocation,
|
|
||||||
|
|
||||||
#[serde(default)]
|
|
||||||
pub duration: CacheDuration,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
impl Default for Cache {
|
||||||
pub struct CacheLocation(PathBuf);
|
|
||||||
|
|
||||||
impl From<PathBuf> for CacheLocation {
|
|
||||||
fn from(value: PathBuf) -> Self {
|
|
||||||
Self(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<CacheLocation> for PathBuf {
|
|
||||||
fn from(value: CacheLocation) -> Self {
|
|
||||||
value.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for CacheLocation {
|
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let home = dirs::home_dir().unwrap_or_default();
|
let home = dirs::home_dir().unwrap_or_default();
|
||||||
|
|
||||||
Self(home.join(".cache/gitnow"))
|
Self {
|
||||||
}
|
location: home.join(".cache/gitnow"),
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
|
||||||
#[serde(untagged)]
|
|
||||||
pub enum CacheDuration {
|
|
||||||
Enabled(bool),
|
|
||||||
Precise {
|
|
||||||
#[serde(default)]
|
|
||||||
days: u64,
|
|
||||||
#[serde(default)]
|
|
||||||
hours: u64,
|
|
||||||
#[serde(default)]
|
|
||||||
minutes: u64,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CacheDuration {
|
|
||||||
pub fn get_duration(&self) -> Option<std::time::Duration> {
|
|
||||||
match self {
|
|
||||||
CacheDuration::Enabled(true) => CacheDuration::default().get_duration(),
|
|
||||||
CacheDuration::Enabled(false) => None,
|
|
||||||
CacheDuration::Precise {
|
|
||||||
days,
|
|
||||||
hours,
|
|
||||||
minutes,
|
|
||||||
} => Some(
|
|
||||||
std::time::Duration::from_days(*days)
|
|
||||||
+ std::time::Duration::from_hours(*hours)
|
|
||||||
+ std::time::Duration::from_mins(*minutes),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for CacheDuration {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::Precise {
|
|
||||||
days: 1,
|
|
||||||
hours: 0,
|
|
||||||
minutes: 0,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -233,7 +174,6 @@ mod test {
|
|||||||
let content = r#"
|
let content = r#"
|
||||||
[settings.cache]
|
[settings.cache]
|
||||||
location = ".cache/gitnow"
|
location = ".cache/gitnow"
|
||||||
duration = { days = 2 }
|
|
||||||
|
|
||||||
[[providers.github]]
|
[[providers.github]]
|
||||||
current_user = "kjuulh"
|
current_user = "kjuulh"
|
||||||
@ -310,12 +250,7 @@ mod test {
|
|||||||
},
|
},
|
||||||
settings: Settings {
|
settings: Settings {
|
||||||
cache: Cache {
|
cache: Cache {
|
||||||
location: PathBuf::from(".cache/gitnow").into(),
|
location: PathBuf::from(".cache/gitnow/")
|
||||||
duration: CacheDuration::Precise {
|
|
||||||
days: 2,
|
|
||||||
hours: 0,
|
|
||||||
minutes: 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -120,6 +120,7 @@ impl GiteaProvider {
|
|||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip(self))]
|
||||||
pub async fn list_repositories_for_user_with_page(
|
pub async fn list_repositories_for_user_with_page(
|
||||||
&self,
|
&self,
|
||||||
user: &str,
|
user: &str,
|
||||||
@ -134,6 +135,7 @@ impl GiteaProvider {
|
|||||||
Ok(repos)
|
Ok(repos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument]
|
||||||
pub async fn list_repositories_for_organisation(
|
pub async fn list_repositories_for_organisation(
|
||||||
&self,
|
&self,
|
||||||
organisation: &str,
|
organisation: &str,
|
||||||
@ -179,6 +181,7 @@ impl GiteaProvider {
|
|||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip(self))]
|
||||||
pub async fn list_repositories_for_organisation_with_page(
|
pub async fn list_repositories_for_organisation_with_page(
|
||||||
&self,
|
&self,
|
||||||
organisation: &str,
|
organisation: &str,
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#![feature(duration_constructors)]
|
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
Loading…
Reference in New Issue
Block a user