account full path in the tantivy
This commit is contained in:
2
client
2
client
Submodule client updated: 15deef1272...4ef069e7b1
Submodule client-gui2 updated: 7511ef2a37...782877f62a
@@ -1,6 +1,6 @@
|
|||||||
mod query_builder;
|
mod query_builder;
|
||||||
|
|
||||||
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
@@ -64,43 +64,16 @@ impl AccountPathProjection {
|
|||||||
profile_name.replace('"', "\"\""),
|
profile_name.replace('"', "\"\""),
|
||||||
LEDGER_ACCOUNTS_TABLE_NAME,
|
LEDGER_ACCOUNTS_TABLE_NAME,
|
||||||
);
|
);
|
||||||
let rows = sqlx::query(AssertSqlSafe(format!(
|
let paths = sqlx::query_as::<_, (i64, String)>(AssertSqlSafe(format!(
|
||||||
"SELECT id, segment, parent_account_id FROM {qualified_accounts} WHERE deleted = FALSE"
|
"SELECT id, full_path
|
||||||
|
FROM {qualified_accounts}
|
||||||
|
WHERE deleted = FALSE"
|
||||||
)))
|
)))
|
||||||
.fetch_all(pool)
|
.fetch_all(pool)
|
||||||
.await
|
.await
|
||||||
.map_err(|error| Status::internal(format!("Account path lookup failed: {error}")))?;
|
.map_err(|error| Status::internal(format!("Account path lookup failed: {error}")))?
|
||||||
let mut nodes = BTreeMap::new();
|
.into_iter()
|
||||||
for row in rows {
|
.collect();
|
||||||
let id: i64 = row.try_get("id").map_err(|error| {
|
|
||||||
Status::internal(format!("Account id read failed: {error}"))
|
|
||||||
})?;
|
|
||||||
let segment: String = row.try_get("segment").map_err(|error| {
|
|
||||||
Status::internal(format!("Account segment read failed: {error}"))
|
|
||||||
})?;
|
|
||||||
let parent: Option<i64> = row.try_get("parent_account_id").map_err(|error| {
|
|
||||||
Status::internal(format!("Account parent read failed: {error}"))
|
|
||||||
})?;
|
|
||||||
nodes.insert(id, (segment, parent));
|
|
||||||
}
|
|
||||||
let mut paths = HashMap::new();
|
|
||||||
for &id in nodes.keys() {
|
|
||||||
let mut segments = Vec::new();
|
|
||||||
let mut visited = BTreeSet::new();
|
|
||||||
let mut current = Some(id);
|
|
||||||
while let Some(node_id) = current {
|
|
||||||
if !visited.insert(node_id) {
|
|
||||||
return Err(Status::internal("Stored account hierarchy contains a cycle"));
|
|
||||||
}
|
|
||||||
let (segment, parent) = nodes.get(&node_id).ok_or_else(|| {
|
|
||||||
Status::internal(format!("Account {node_id} was not found"))
|
|
||||||
})?;
|
|
||||||
segments.push(segment.clone());
|
|
||||||
current = *parent;
|
|
||||||
}
|
|
||||||
segments.reverse();
|
|
||||||
paths.insert(id, segments.join("/"));
|
|
||||||
}
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
paths,
|
paths,
|
||||||
account_column,
|
account_column,
|
||||||
|
|||||||
2
server
2
server
Submodule server updated: 19d6545ed4...c51ead9a19
Reference in New Issue
Block a user