| 58 | |
| 59 | impl FetchStats { |
| 60 | pub async fn call<C>(&self, git: &Client, cache: &C) -> Result<FetchStatsResult> |
| 61 | where |
| 62 | C: CacheStats + Clone + Send + std::fmt::Debug + 'static, |
| 63 | { |
| 64 | let mut stats = vec![]; |
| 65 | |
| 66 | for &repo_id in self.viewer.read_repo_ids.iter() { |
| 67 | let view = git.view(repo_id)?; |
| 68 | |
| 69 | let commit = view.commit.to_string(); |
| 70 | let s = match cache.fetch(repo_id, &commit)? { |
| 71 | Some(stats) => stats, |
| 72 | |
| 73 | None => { |
| 74 | let stats = RepoStats { |
| 75 | computing: true, |
| 76 | link_count: None, |
| 77 | topic_count: None, |
| 78 | }; |
| 79 | // Save a placeholder that will be updated with the computed values. Expires |
| 80 | // after 180 seconds in case something happens and it should be retried. |
| 81 | cache.save(repo_id, &commit, &stats, Some(120))?; |
| 82 | |
| 83 | // let view = view.duplicate()?; |
| 84 | // let cache = cache.to_owned(); |
| 85 | // let commit = commit.to_owned(); |
| 86 | // let prefix = repo_id.to_owned(); |
| 87 | |
| 88 | // let _ = actix_web::web::block(move || { |
| 89 | // let key = format!("{}:{}", prefix, commit); |
| 90 | // log::info!("computing stats for {} ...", key); |
| 91 | // let stats = view.stats().expect("failed to fetch stats"); |
| 92 | // cache |
| 93 | // .save(&prefix, &commit, &stats, None) |
| 94 | // .expect("failed to save stats"); |
| 95 | // log::info!("stats for {} saved to cache", key); |
| 96 | // }); |
| 97 | |
| 98 | stats |
| 99 | } |
| 100 | }; |
| 101 | |
| 102 | stats.push(s); |
| 103 | } |
| 104 | |
| 105 | Ok(FetchStatsResult { |
| 106 | stats: Stats { stats }, |
| 107 | }) |
| 108 | } |
| 109 | } |