fix: import page search filters by source=tangled, sorted by stars
Author: Aaron Steven White
Commit
07f8db5a6bf462be8c9d2770b0396984a98bfa7cParent: 7b096a8606
Structural diff unavailable
These commits were pushed via plain git push, so no pre-parsed
schemas are available. Install git-remote-cospan and re-push via panproto:// to
see scope-level changes, breaking change detection, and semantic diffs.
brew install panproto/tap/git-remote-cospan4 files changed +25 -20
@@ -93,7 +93,7 @@
9393 } 9494 searching = true; 9595 try { 96- const result = await listRepos({ query, limit: 30 }); 96+ const result = await listRepos({ query, source: 'tangled', limit: 30 }); 9797 allRepos = result.items; 9898 cursor = result.cursor; 9999 resolveAllHandles(result.items);
@@ -189,41 +189,46 @@ pub async fn ensure_exists(
189189 pub async fn search( 190190 pool: &PgPool, 191191 query: &str, 192+ source: Option<&str>, 192193 limit: i64, 193194 cursor: Option<&str>, 194195 ) -> Result<Vec<RepoRow>, sqlx::Error> { 196+ let source_clause = if source.is_some() { "AND source = $4" } else { "" }; 195197 if let Some(cursor_ts) = cursor { 196198 let ts: DateTime<Utc> = cursor_ts 197199 .parse() 198200 .map_err(|_| sqlx::Error::Protocol("invalid cursor".into()))?; 199- sqlx::query_as::<_, RepoRow>( 201+ let sql = format!( 200202 "SELECT did, rkey, name, description, protocol, node_did, node_url, \ 201203 default_branch, visibility, source_repo, star_count, fork_count, \ 202204 open_issue_count, open_mr_count, source, source_uri, created_at, indexed_at \ 203205 FROM repos \ 204206 WHERE to_tsvector('english', coalesce(name, '') || ' ' || coalesce(description, '')) \ 205207 @@ plainto_tsquery('english', $1) \ 206- AND created_at < $2 \ 207- ORDER BY created_at DESC LIMIT $3", 208- ) 209- .bind(query) 210- .bind(ts) 211- .bind(limit) 212- .fetch_all(pool) 213- .await 208+ AND created_at < $2 {source_clause} \ 209+ ORDER BY star_count DESC, created_at DESC LIMIT $3" 210+ ); 211+ let mut q = sqlx::query_as::<_, RepoRow>(&sql) 212+ .bind(query) 213+ .bind(ts) 214+ .bind(limit); 215+ if let Some(s) = source { q = q.bind(s); } 216+ q.fetch_all(pool).await 214217 } else { 215- sqlx::query_as::<_, RepoRow>( 218+ let source_clause = if source.is_some() { "AND source = $3" } else { "" }; 219+ let sql = format!( 216220 "SELECT did, rkey, name, description, protocol, node_did, node_url, \ 217221 default_branch, visibility, source_repo, star_count, fork_count, \ 218222 open_issue_count, open_mr_count, source, source_uri, created_at, indexed_at \ 219223 FROM repos \ 220224 WHERE to_tsvector('english', coalesce(name, '') || ' ' || coalesce(description, '')) \ 221- @@ plainto_tsquery('english', $1) \ 222- ORDER BY created_at DESC LIMIT $2", 223- ) 224- .bind(query) 225- .bind(limit) 226- .fetch_all(pool) 227- .await 225+ @@ plainto_tsquery('english', $1) {source_clause} \ 226+ ORDER BY star_count DESC, created_at DESC LIMIT $2" 227+ ); 228+ let mut q = sqlx::query_as::<_, RepoRow>(&sql) 229+ .bind(query) 230+ .bind(limit); 231+ if let Some(s) = source { q = q.bind(s); } 232+ q.fetch_all(pool).await 228233 } 229234 }
@@ -27,7 +27,7 @@ pub async fn handler(
2727 2828 let repos = if let Some(query) = ¶ms.query { 2929 if !query.trim().is_empty() { 30- db::repo::search(&state.db, query, limit + 1, params.cursor.as_deref()).await? 30+ db::repo::search(&state.db, query, params.source.as_deref(), limit + 1, params.cursor.as_deref()).await? 3131 } else { 3232 db::repo::list_recent(&state.db, limit + 1, params.cursor.as_deref()).await? 3333 }
@@ -21,7 +21,7 @@ pub async fn handler(
2121 ) -> Result<Json<serde_json::Value>, AppError> { 2222 let limit = params.limit.unwrap_or(25).min(100); 2323 24- let repos = db::repo::search(&state.db, ¶ms.q, limit + 1, params.cursor.as_deref()).await?; 24+ let repos = db::repo::search(&state.db, ¶ms.q, None, limit + 1, params.cursor.as_deref()).await?; 2525 2626 let has_more = repos.len() as i64 > limit; 2727 let repos: Vec<_> = repos.into_iter().take(limit as usize).collect();