Skip to content

Commit

Permalink
Fix ordering of latest_top_ups (#7046)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Dec 12, 2024
1 parent 3018eaa commit a1dc62f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions backend/canisters/cycles_dispenser/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- Expose size of each virtual stable memory in metrics ([#6981](https://github.com/open-chat-labs/open-chat/pull/6981))

### Fixed

- Fix ordering of `latest_top_ups` ([#7046](https://github.com/open-chat-labs/open-chat/pull/7046))

## [[2.0.1485](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1485-cycles_dispenser)] - 2024-11-29

### Added
Expand Down
12 changes: 8 additions & 4 deletions backend/canisters/cycles_dispenser/impl/src/model/canisters.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use std::cmp::Reverse;
use std::collections::hash_map::Entry::Vacant;
use std::collections::{BinaryHeap, HashMap};
use types::{CanisterId, Cycles, TimestampMillis};
Expand Down Expand Up @@ -67,14 +68,17 @@ impl Canisters {
})
}) {
if heap.len() < count {
heap.push(top_up);
} else if top_up > *heap.peek().unwrap() {
heap.push(Reverse(top_up));
} else if top_up > heap.peek().unwrap().0 {
heap.pop();
heap.push(top_up);
heap.push(Reverse(top_up));
}
}

let mut vec = heap.into_sorted_vec();
let mut vec = Vec::with_capacity(heap.len());
while let Some(Reverse(top_up)) = heap.pop() {
vec.push(top_up);
}
vec.reverse();
vec
}
Expand Down

0 comments on commit a1dc62f

Please sign in to comment.