Better accounting data retrieve

This commit is contained in:
Dominik Werder
2024-06-27 11:03:57 +02:00
parent 8e286b455d
commit 21259e6591
14 changed files with 456 additions and 220 deletions
+6 -6
View File
@@ -19,13 +19,13 @@ pub struct ChannelInfo {
pub kind: u16,
}
pub async fn info_for_series_ids(series_ids: &[u64], pg: &Client) -> Result<Vec<(u64, Option<ChannelInfo>)>, Error> {
pub async fn info_for_series_ids(series_ids: &[u64], pg: &Client) -> Result<Vec<Option<ChannelInfo>>, Error> {
let (ord, seriess) = series_ids
.iter()
.enumerate()
.fold((Vec::new(), Vec::new()), |mut a, x| {
a.0.push(x.0 as i32);
a.1.push(*x.1 as i64);
.fold((Vec::new(), Vec::new()), |mut a, (i, &series)| {
a.0.push(i as i32);
a.1.push(series as i64);
a
});
let sql = concat!(
@@ -62,9 +62,9 @@ pub async fn info_for_series_ids(series_ids: &[u64], pg: &Client) -> Result<Vec<
shape,
kind,
};
ret.push((series, Some(e)));
ret.push(Some(e));
} else {
ret.push((series, None));
ret.push(None);
}
}
Ok(ret)
+20
View File
@@ -29,6 +29,10 @@ impl err::ToErr for Error {
enum Job {
ChConfBestMatchingNameRange(String, String, NanoRange, Sender<Result<ChConf, Error>>),
ChConfForSeries(String, u64, Sender<Result<ChConf, Error>>),
InfoForSeriesIds(
Vec<u64>,
Sender<Result<Vec<Option<crate::channelinfo::ChannelInfo>>, crate::channelinfo::Error>>,
),
}
#[derive(Debug, Clone)]
@@ -59,6 +63,16 @@ impl PgQueue {
self.tx.send(job).await.map_err(|_| Error::ChannelSend)?;
Ok(rx)
}
pub async fn info_for_series_ids(
&self,
series_ids: Vec<u64>,
) -> Result<Receiver<Result<Vec<Option<crate::channelinfo::ChannelInfo>>, crate::channelinfo::Error>>, Error> {
let (tx, rx) = async_channel::bounded(1);
let job = Job::InfoForSeriesIds(series_ids, tx);
self.tx.send(job).await.map_err(|_| Error::ChannelSend)?;
Ok(rx)
}
}
#[derive(Debug)]
@@ -106,6 +120,12 @@ impl PgWorker {
// TODO count for stats
}
}
Job::InfoForSeriesIds(ids, tx) => {
let res = crate::channelinfo::info_for_series_ids(&ids, &self.pg).await;
if tx.send(res.map_err(Into::into)).await.is_err() {
// TODO count for stats
}
}
}
}
}