Cache channel listings for search
Search keeps each channel's list for an hour, so a repeat needs no network, and uses the old copy with a warning if the registry fails. `--refresh` skips the cache; publish, index, login and logout drop it. A test command no longer writes to stdout, where it could corrupt the test runner's results. Planning: bnbr1 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8f202290b9
commit
47a80fad04
9 files changed
+330
-55
No files matched your search
+35
-13
@@ -23,7 +23,7 @@ struct IndexEntry {
|
||||
}
|
||||
|
||||
///|
|
||||
fn index_json(entries : Array[IndexEntry]) -> String {
|
||||
fn index_object(entries : Array[IndexEntry]) -> Map[String, Json] {
|
||||
let sorted = entries.copy()
|
||||
sorted.sort_by(fn(a, b) { a.name.lexical_compare(b.name) })
|
||||
let pkgs : Array[Json] = []
|
||||
@@ -37,7 +37,12 @@ fn index_json(entries : Array[IndexEntry]) -> String {
|
||||
}
|
||||
let top : Map[String, Json] = Map([])
|
||||
top["packages"] = Json::array(pkgs)
|
||||
Json::object(top).stringify() + "\n"
|
||||
top
|
||||
}
|
||||
|
||||
///|
|
||||
fn index_json(entries : Array[IndexEntry]) -> String {
|
||||
Json::object(index_object(entries)).stringify() + "\n"
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -204,12 +209,15 @@ fn find_entry(entries : Array[IndexEntry], name : String) -> IndexEntry? {
|
||||
}
|
||||
|
||||
///|
|
||||
/// Read every named package. One that can't be read keeps its old entry.
|
||||
async fn build_index(
|
||||
/// Read every named package. Returns those found, and the names that couldn't
|
||||
/// be read with the reason.
|
||||
async fn read_entries(
|
||||
ch : Channel,
|
||||
names : Array[String],
|
||||
old : Array[IndexEntry],
|
||||
) -> Array[IndexEntry] raise OrbitError {
|
||||
) -> (Array[IndexEntry], Array[(String, String)]) raise OrbitError {
|
||||
if names.length() == 0 {
|
||||
return ([], [])
|
||||
}
|
||||
let results : Array[(String, Result[IndexEntry?, String])] = []
|
||||
with_spinner("Reading \{names.length()} repositories in \{ch.name}", () => {
|
||||
@async.with_task_group(group => {
|
||||
@@ -229,17 +237,31 @@ async fn build_index(
|
||||
})
|
||||
})
|
||||
let out : Array[IndexEntry] = []
|
||||
let failed : Array[(String, String)] = []
|
||||
for r in results {
|
||||
match r {
|
||||
(_, Ok(Some(e))) => out.push(e)
|
||||
(_, Ok(None)) => ()
|
||||
(n, Err(msg)) => {
|
||||
println("warning: cannot read '\{n}': \{msg}")
|
||||
match find_entry(old, n) {
|
||||
Some(e) => out.push(e)
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
(n, Err(msg)) => failed.push((n, msg))
|
||||
}
|
||||
}
|
||||
(out, failed)
|
||||
}
|
||||
|
||||
///|
|
||||
/// Read every named package. One that can't be read keeps its old entry.
|
||||
async fn build_index(
|
||||
ch : Channel,
|
||||
names : Array[String],
|
||||
old : Array[IndexEntry],
|
||||
) -> Array[IndexEntry] raise OrbitError {
|
||||
let (out, failed) = read_entries(ch, names)
|
||||
for f in failed {
|
||||
let (n, msg) = f
|
||||
println("warning: cannot read '\{n}': \{msg}")
|
||||
match find_entry(old, n) {
|
||||
Some(e) => out.push(e)
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
out
|
||||
|
||||
Reference in new issue
Block a user