mirror of
https://git.alemi.dev/dashboard.git
synced 2024-11-22 07:24:52 +01:00
fix: way better points fetching
This commit is contained in:
parent
0939e66c2d
commit
66b43551bd
1 changed files with 5 additions and 5 deletions
|
@ -239,11 +239,11 @@ impl AppState {
|
||||||
pub async fn flush_data(&mut self, db: &DatabaseConnection) -> Result<(), DbErr> {
|
pub async fn flush_data(&mut self, db: &DatabaseConnection) -> Result<(), DbErr> {
|
||||||
let now = Utc::now().timestamp();
|
let now = Utc::now().timestamp();
|
||||||
self.fetch(db).await?;
|
self.fetch(db).await?;
|
||||||
let new_width = *self.width.borrow() * 60; // TODO it's in minutes somewhere...
|
self.last_width = *self.width.borrow() * 60; // TODO it's in minutes somewhere...
|
||||||
self.points = entities::points::Entity::find()
|
self.points = entities::points::Entity::find()
|
||||||
.filter(
|
.filter(
|
||||||
Condition::all()
|
Condition::all()
|
||||||
.add(entities::points::Column::X.gte((now - new_width) as f64))
|
.add(entities::points::Column::X.gte((now - self.last_width) as f64))
|
||||||
.add(entities::points::Column::X.lte(now as f64))
|
.add(entities::points::Column::X.lte(now as f64))
|
||||||
)
|
)
|
||||||
.order_by(entities::points::Column::X, Order::Asc)
|
.order_by(entities::points::Column::X, Order::Asc)
|
||||||
|
@ -278,8 +278,8 @@ impl AppState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch new points
|
// fetch new points, use last_width otherwise it fetches same points as above
|
||||||
let lower_bound = std::cmp::max(self.last_check, now - new_width);
|
let lower_bound = std::cmp::max(self.last_check, now - self.last_width);
|
||||||
let new_points = entities::points::Entity::find()
|
let new_points = entities::points::Entity::find()
|
||||||
.filter(
|
.filter(
|
||||||
Condition::all()
|
Condition::all()
|
||||||
|
@ -297,7 +297,7 @@ impl AppState {
|
||||||
|
|
||||||
// remove old points
|
// remove old points
|
||||||
while let Some(p) = self.points.get(0) {
|
while let Some(p) = self.points.get(0) {
|
||||||
if (p.x as i64) >= now - (*self.width.borrow() * 60) {
|
if (p.x as i64) >= now - new_width {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
self.points.pop_front();
|
self.points.pop_front();
|
||||||
|
|
Loading…
Reference in a new issue