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
+12
-36
@@ -879,7 +879,11 @@ fn printable(s : String) -> String {
|
||||
}
|
||||
|
||||
///|
|
||||
async fn cmd_search(ctx : Ctx, term : String) -> Unit raise OrbitError {
|
||||
async fn cmd_search(
|
||||
ctx : Ctx,
|
||||
term : String,
|
||||
refresh? : Bool = false,
|
||||
) -> Unit raise OrbitError {
|
||||
let rows : Array[Array[String]] = [
|
||||
["PACKAGE", "CHANNEL", "VERSION", "DESCRIPTION"],
|
||||
]
|
||||
@@ -894,43 +898,15 @@ async fn cmd_search(ctx : Ctx, term : String) -> Unit raise OrbitError {
|
||||
}
|
||||
let term_lower = ascii_lower(term)
|
||||
for ch in ctx.channels {
|
||||
// Without a usable index, ask the registry's catalog.
|
||||
let index = load_index(ch) catch {
|
||||
OrbitError(msg) => {
|
||||
println("warning: cannot read index of channel '\{ch.name}': \{msg}")
|
||||
None
|
||||
}
|
||||
}
|
||||
if index is Some(entries) {
|
||||
listed = listed + 1
|
||||
for e in entries {
|
||||
if contains_str(e.name, term_lower) ||
|
||||
contains_str(ascii_lower(e.description), term_lower) {
|
||||
add(e.name, ch, e.version, e.description)
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
let repos = list_repos(ch) catch {
|
||||
OrbitError(msg) => {
|
||||
println("warning: cannot list channel '\{ch.name}': \{msg}")
|
||||
continue
|
||||
}
|
||||
let entries = match channel_listing(ctx.root, ch, term_lower, refresh) {
|
||||
Some(es) => es
|
||||
None => continue
|
||||
}
|
||||
listed = listed + 1
|
||||
let candidates : Array[String] = []
|
||||
for r in repos {
|
||||
// A name with "/" is a nested channel namespace (e.g. example/greet under
|
||||
// main), not a package name that `orbit install` could use.
|
||||
if valid_name(r) && r != INDEX_NAME && contains_str(r, term_lower) {
|
||||
candidates.push(r)
|
||||
}
|
||||
}
|
||||
let found = find_orbit_repos(ch, candidates)
|
||||
for i, r in candidates {
|
||||
match found[i] {
|
||||
Some(info) => add(r, ch, info.version, info.description)
|
||||
None => ()
|
||||
for e in entries {
|
||||
if contains_str(e.name, term_lower) ||
|
||||
contains_str(ascii_lower(e.description), term_lower) {
|
||||
add(e.name, ch, e.version, e.description)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user