20260718 重构 RPKI Explorer 查询界面
This commit is contained in:
137
src/query_db.rs
137
src/query_db.rs
@@ -473,6 +473,31 @@ impl QueryDb {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn list_objects_filtered(
|
||||
&self,
|
||||
run_id: &str,
|
||||
scope: ObjectScope,
|
||||
filter: &report_stream::ObjectFilter,
|
||||
limit: usize,
|
||||
cursor: Option<&str>,
|
||||
) -> QueryDbResult<QueryPage<ObjectInstanceRecord>> {
|
||||
let Some(report_path) = self.report_path_for_run(run_id)? else {
|
||||
return Ok(QueryPage {
|
||||
data: Vec::new(),
|
||||
next_cursor: None,
|
||||
limit: limit.clamp(1, 1000),
|
||||
});
|
||||
};
|
||||
report_stream::list_report_objects_filtered(
|
||||
&report_path,
|
||||
run_id,
|
||||
scope,
|
||||
filter,
|
||||
limit,
|
||||
cursor,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn get_object_by_instance_id(
|
||||
&self,
|
||||
run_id: &str,
|
||||
@@ -628,6 +653,118 @@ impl QueryDb {
|
||||
self.get_json_cf(CF_OBJECTS_BY_HASH, object_hash_key(sha256).as_bytes())
|
||||
}
|
||||
|
||||
pub fn search_object_projections_by_hash_prefix(
|
||||
&self,
|
||||
sha256_prefix: &str,
|
||||
limit: usize,
|
||||
) -> QueryDbResult<Vec<crate::object_projection::ObjectProjectionRecord>> {
|
||||
let cf = self.cf(CF_OBJECTS_BY_HASH)?;
|
||||
let prefix = format!("objhash/{sha256_prefix}");
|
||||
let mut out = Vec::new();
|
||||
let mode = IteratorMode::From(prefix.as_bytes(), rocksdb::Direction::Forward);
|
||||
for item in self.db.iterator_cf(cf, mode) {
|
||||
let (key, value) = item?;
|
||||
if !String::from_utf8_lossy(&key).starts_with(&prefix) {
|
||||
break;
|
||||
}
|
||||
if out.len() >= limit {
|
||||
break;
|
||||
}
|
||||
out.push(serde_json::from_slice(&value)?);
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
pub fn get_cached_object_by_sha256(
|
||||
&self,
|
||||
run_id: &str,
|
||||
sha256: &str,
|
||||
) -> QueryDbResult<Option<ObjectInstanceRecord>> {
|
||||
let mut cursor = None;
|
||||
loop {
|
||||
let page: QueryPage<ObjectInstanceRecord> = self.list_json_by_prefix(
|
||||
CF_OBJECT_INSTANCES,
|
||||
&format!("objinst/{run_id}/"),
|
||||
1000,
|
||||
cursor.as_deref(),
|
||||
)?;
|
||||
if let Some(found) = page
|
||||
.data
|
||||
.into_iter()
|
||||
.find(|item| item.sha256.eq_ignore_ascii_case(sha256))
|
||||
{
|
||||
return Ok(Some(found));
|
||||
}
|
||||
let Some(next_cursor) = page.next_cursor else {
|
||||
return Ok(None);
|
||||
};
|
||||
cursor = Some(next_cursor);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn search_repos(
|
||||
&self,
|
||||
run_id: &str,
|
||||
query_lower: &str,
|
||||
limit: usize,
|
||||
) -> QueryDbResult<Vec<RepositoryRecord>> {
|
||||
let cf = self.cf(CF_REPOS)?;
|
||||
let prefix = format!("repo/{run_id}/");
|
||||
let mut out = Vec::new();
|
||||
let mode = IteratorMode::From(prefix.as_bytes(), rocksdb::Direction::Forward);
|
||||
for item in self.db.iterator_cf(cf, mode) {
|
||||
let (key, value) = item?;
|
||||
if !String::from_utf8_lossy(&key).starts_with(&prefix) {
|
||||
break;
|
||||
}
|
||||
if out.len() >= limit {
|
||||
break;
|
||||
}
|
||||
let repo: RepositoryRecord = serde_json::from_slice(&value)?;
|
||||
if repo.host.to_lowercase().contains(query_lower)
|
||||
|| repo.uri.to_lowercase().contains(query_lower)
|
||||
{
|
||||
out.push(repo);
|
||||
}
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
pub fn search_publication_points(
|
||||
&self,
|
||||
run_id: &str,
|
||||
query_lower: &str,
|
||||
limit: usize,
|
||||
) -> QueryDbResult<Vec<PublicationPointRecord>> {
|
||||
let cf = self.cf(CF_PUBLICATION_POINTS)?;
|
||||
let prefix = format!("pp/{run_id}/");
|
||||
let mut out = Vec::new();
|
||||
let mode = IteratorMode::From(prefix.as_bytes(), rocksdb::Direction::Forward);
|
||||
for item in self.db.iterator_cf(cf, mode) {
|
||||
let (key, value) = item?;
|
||||
if !String::from_utf8_lossy(&key).starts_with(&prefix) {
|
||||
break;
|
||||
}
|
||||
if out.len() >= limit {
|
||||
break;
|
||||
}
|
||||
let pp: PublicationPointRecord = serde_json::from_slice(&value)?;
|
||||
let uri_matches = [
|
||||
pp.manifest_rsync_uri.as_deref(),
|
||||
pp.publication_point_rsync_uri.as_deref(),
|
||||
pp.rrdp_notification_uri.as_deref(),
|
||||
pp.rsync_base_uri.as_deref(),
|
||||
]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.any(|uri| uri.to_lowercase().contains(query_lower));
|
||||
if uri_matches {
|
||||
out.push(pp);
|
||||
}
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
pub fn get_stat(
|
||||
&self,
|
||||
run_id: &str,
|
||||
|
||||
Reference in New Issue
Block a user