collin/anvil · 80bf8535
Trigger language indexing on repository push
Collin Richards · 2026-08-18 01:11 UTC · 80bf8535f5cb3c1225f87f47a863cf228ca2091d · parent 2bc1657f · browse files
modifiedcrates/anvil-core/src/periodic.rs+16 −0
| ⋯ 146 unchanged lines | |||
| 147 | 147 | } | |
| 148 | 148 | } | |
| 149 | 149 | ||
| 150 | + | /// Trigger language detection for a single repository, updating its LOC percentages. | |
| 151 | + | /// This is called immediately after a push to keep metadata current without waiting for | |
| 152 | + | /// the periodic job interval. Spawned as a background task so it doesn't block the push response. | |
| 153 | + | pub fn trigger_repo_indexing(app: App, repo_id: i64, repo_path: std::path::PathBuf) { | |
| 154 | + | tokio::spawn(async move { | |
| 155 | + | let repo_git_path = repo_path.join(".git"); | |
| 156 | + | if repo_git_path.exists() | |
| 157 | + | && let Ok(detection) = language::detect(&repo_git_path).await | |
| 158 | + | && let Err(e) = | |
| 159 | + | repos::update_languages(&app.db, repo_id, &detection.primary, &detection.json).await | |
| 160 | + | { | |
| 161 | + | tracing::warn!(repo_id = repo_id, error = %e, "failed to update languages after push"); | |
| 162 | + | } | |
| 163 | + | }); | |
| 164 | + | } | |
| 165 | + | ||
| 150 | 166 | /// Try to extract the first image URL from a repository's README file. | |
| 151 | 167 | /// Scans the repository for a README file, reads it, and returns the first image URL found. | |
| 152 | 168 | async fn extract_readme_image(repo_path: &Path) -> Option<String> { | |
| ⋯ 21 unchanged lines | |||
modifiedcrates/anvil-web/src/git_http.rs+2 −0
| ⋯ 16 unchanged lines | |||
| 17 | 17 | App, | |
| 18 | 18 | Repository, | |
| 19 | 19 | access, | |
| 20 | + | periodic, | |
| 20 | 21 | repos, | |
| 21 | 22 | users, | |
| 22 | 23 | }; | |
| ⋯ 257 unchanged lines | |||
| 280 | 281 | if !meta.mirror_url.is_empty() { | |
| 281 | 282 | anvil_git::mirror::spawn_push(path.clone(), meta.mirror_url.clone()); | |
| 282 | 283 | } | |
| 284 | + | periodic::trigger_repo_indexing(app.clone(), meta.id, path); | |
| 283 | 285 | rpc_response(Service::ReceivePack.result_content_type(), Body::from(b)) | |
| 284 | 286 | } | |
| 285 | 287 | Err(e) => internal(e), | |
| ⋯ 2 unchanged lines | |||