mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-30 20:37:36 +00:00
refactor: Use concrete UserPowerLevel type
This commit is contained in:
1 parent
f97cfa12ac
commit
c0ee45192a
4 files changed
+13
-13
No files matched your search
@@ -16,6 +16,7 @@ use ruma::{
|
||||
room::{
|
||||
join_rules::{JoinRule, RoomJoinRulesEventContent},
|
||||
member::{MembershipState, RoomMemberEventContent},
|
||||
power_levels::UserPowerLevel,
|
||||
},
|
||||
},
|
||||
int, room_id, uint, user_id,
|
||||
@@ -46,7 +47,7 @@ fn lexico_topo_sort(c: &mut test::Bencher) {
|
||||
|
||||
c.iter(|| {
|
||||
let _ = state_res::lexicographical_topological_sort(&graph, &|_| {
|
||||
future::ok((int!(0), MilliSecondsSinceUnixEpoch(uint!(0))))
|
||||
future::ok((UserPowerLevel::Int(int!(0)), MilliSecondsSinceUnixEpoch(uint!(0))))
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -442,29 +442,27 @@ where
|
||||
/// `key_fn` is used as to obtain the power level and age of an event for
|
||||
/// breaking ties (together with the event ID).
|
||||
#[tracing::instrument(level = "debug", skip_all)]
|
||||
pub async fn lexicographical_topological_sort<Id, P, F, Fut, Hasher, S>(
|
||||
pub async fn lexicographical_topological_sort<Id, F, Fut, Hasher, S>(
|
||||
graph: &HashMap<Id, HashSet<Id, Hasher>, S>,
|
||||
key_fn: &F,
|
||||
) -> Result<Vec<Id>>
|
||||
where
|
||||
F: Fn(Id) -> Fut + Sync,
|
||||
Fut: Future<Output = Result<(P, MilliSecondsSinceUnixEpoch)>> + Send,
|
||||
Fut: Future<Output = Result<(UserPowerLevel, MilliSecondsSinceUnixEpoch)>> + Send,
|
||||
Id: Borrow<EventId> + Clone + Eq + Hash + Ord + Send + Sync,
|
||||
P: Ord + Send,
|
||||
Hasher: BuildHasher + Default + Clone + Send + Sync,
|
||||
S: BuildHasher + Clone + Send + Sync,
|
||||
{
|
||||
#[derive(PartialEq, Eq)]
|
||||
struct TieBreaker<'a, Id, P> {
|
||||
power_level: P,
|
||||
struct TieBreaker<'a, Id> {
|
||||
power_level: UserPowerLevel,
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||
event_id: &'a Id,
|
||||
}
|
||||
|
||||
impl<Id, P> Ord for TieBreaker<'_, Id, P>
|
||||
impl<Id> Ord for TieBreaker<'_, Id>
|
||||
where
|
||||
Id: Ord,
|
||||
P: Ord,
|
||||
{
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
// NOTE: the power level comparison is "backwards" intentionally.
|
||||
@@ -482,10 +480,9 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<Id, P> PartialOrd for TieBreaker<'_, Id, P>
|
||||
impl<Id> PartialOrd for TieBreaker<'_, Id>
|
||||
where
|
||||
Id: Ord,
|
||||
P: Ord,
|
||||
{
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }
|
||||
}
|
||||
@@ -2078,7 +2075,7 @@ mod tests {
|
||||
};
|
||||
|
||||
let res = super::lexicographical_topological_sort(&graph, &|_id| async {
|
||||
Ok((int!(0), MilliSecondsSinceUnixEpoch(uint!(0))))
|
||||
Ok((UserPowerLevel::Int(int!(0)), MilliSecondsSinceUnixEpoch(uint!(0))))
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -13,6 +13,7 @@ use ruma::{
|
||||
room::{
|
||||
join_rules::{JoinRule, RoomJoinRulesEventContent},
|
||||
member::{MembershipState, RoomMemberEventContent},
|
||||
power_levels::UserPowerLevel,
|
||||
},
|
||||
},
|
||||
int, room_id,
|
||||
@@ -89,7 +90,7 @@ pub(crate) async fn do_check(
|
||||
// Resolve the current state and add it to the state_at_event map then
|
||||
// continue on in "time"
|
||||
for node in super::lexicographical_topological_sort(&graph, &|_id| async {
|
||||
Ok((int!(0), MilliSecondsSinceUnixEpoch(uint!(0))))
|
||||
Ok((UserPowerLevel::Int(int!(0)), MilliSecondsSinceUnixEpoch(uint!(0))))
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
|
||||
@@ -20,6 +20,7 @@ use ruma::{
|
||||
CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId,
|
||||
OwnedServerName, RoomId, ServerName, UInt,
|
||||
api::federation::event::{get_event, get_missing_events},
|
||||
events::room::power_levels::UserPowerLevel,
|
||||
int,
|
||||
room_version_rules::RoomVersionRules,
|
||||
};
|
||||
@@ -100,7 +101,7 @@ pub async fn build_local_dag(
|
||||
// order events correctly for processing, however ultimately that
|
||||
// should be the sender's job.
|
||||
let ts = id_origin_ts.get(&node_id).copied().unwrap_or_default();
|
||||
Ok((int!(0), MilliSecondsSinceUnixEpoch(ts)))
|
||||
Ok((UserPowerLevel::Int(int!(0)), MilliSecondsSinceUnixEpoch(ts)))
|
||||
})
|
||||
.await
|
||||
.inspect(|sorted| {
|
||||
|
||||
Reference in new issue
Block a user