Skip to content

Commit

Permalink
Merge pull request #1535 from dedis/work-fe1-mgreub-high-cpu-usage
Browse files Browse the repository at this point in the history
Fix performance issues
  • Loading branch information
MeKHell authored May 3, 2023
2 parents 03dbaaf + aaa61d8 commit 77daa26
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,75 @@ exports[`EventRollCall render correctly no duplicate attendees opened roll calls
>
The Roll Call is currently open and you as an attendee should let the organizer scan your PoP token encoded in the QR Code below.
</Text>
<qrcode
overlayText="Scan to add attendee"
value="{"pop_token":""}"
/>
<View
style={
{
"flexDirection": "row",
"justifyContent": "center",
}
}
>
<View
style={
{
"position": "relative",
}
}
>
<qrcode
level="H"
size={256}
style={
{
"height": "auto",
"maxWidth": "300px",
"width": "100%",
}
}
value="{"pop_token":""}"
viewBox="0 0 256 256"
/>
<View
style={
{
"alignItems": "center",
"backgroundColor": "#3742fa",
"borderRadius": 100,
"bottom": "27.9%",
"display": "flex",
"justifyContent": "center",
"left": "27.9%",
"overflow": "hidden",
"padding": "4",
"position": "absolute",
"right": "27.9%",
"top": "27.9%",
}
}
>
<Text
style={
[
{
"color": "#000",
"fontSize": 20,
"lineHeight": 26,
"textAlign": "left",
},
{
"textAlign": "center",
},
{
"color": "#fff",
},
]
}
>
Scan to add attendee
</Text>
</View>
</View>
</View>
<View
style={
{
Expand Down Expand Up @@ -1310,10 +1375,75 @@ exports[`EventRollCall render correctly no duplicate attendees re-opened roll ca
>
The Roll Call is currently open and you as an attendee should let the organizer scan your PoP token encoded in the QR Code below.
</Text>
<qrcode
overlayText="Scan to add attendee"
value="{"pop_token":""}"
/>
<View
style={
{
"flexDirection": "row",
"justifyContent": "center",
}
}
>
<View
style={
{
"position": "relative",
}
}
>
<qrcode
level="H"
size={256}
style={
{
"height": "auto",
"maxWidth": "300px",
"width": "100%",
}
}
value="{"pop_token":""}"
viewBox="0 0 256 256"
/>
<View
style={
{
"alignItems": "center",
"backgroundColor": "#3742fa",
"borderRadius": 100,
"bottom": "27.9%",
"display": "flex",
"justifyContent": "center",
"left": "27.9%",
"overflow": "hidden",
"padding": "4",
"position": "absolute",
"right": "27.9%",
"top": "27.9%",
}
}
>
<Text
style={
[
{
"color": "#000",
"fontSize": 20,
"lineHeight": 26,
"textAlign": "left",
},
{
"textAlign": "center",
},
{
"color": "#fff",
},
]
}
>
Scan to add attendee
</Text>
</View>
</View>
</View>
<View
style={
{
Expand Down
39 changes: 27 additions & 12 deletions fe1-web/src/features/witness/network/WitnessStoreWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ export const afterMessageProcessingHandler =
* being called after every dispatch(). Thus it is possible that a
* message has skipped unprocessedIds and we have to check allIds as well
* @param store The redux store
* @param getCurrentLaoId A function that returns the current LAO id
* @param afterProcessingHandler The function to execute
* @returns The listener that can be passed to store.subscribe()
*/
export const makeWitnessStoreWatcher = (
Expand All @@ -121,6 +123,9 @@ export const makeWitnessStoreWatcher = (

let currentAllIds: string[] = [];
let currentUnprocessedIds: string[] = [];
const laoToWitnessableId: Record<string, string[]> = {};
let lastLaoId: Hash | undefined;

return () => {
const laoId = getCurrentLaoId();
// we have to be careful with ExtendedMessage.fromState
Expand All @@ -135,7 +140,7 @@ export const makeWitnessStoreWatcher = (

const msgState = getMessagesState(state);
const allIds = msgState?.allIds || [];
previousAllIds = currentAllIds || [];
previousAllIds = currentAllIds;
currentAllIds = allIds;

const unprocessedIds = msgState?.unprocessedIds || [];
Expand All @@ -152,21 +157,31 @@ export const makeWitnessStoreWatcher = (
return;
}

const messagesToWitness = currentAllIds.filter(
let messagesToWitness = currentAllIds.filter(
(msgId) =>
!currentUnprocessedIds.includes(msgId) &&
(!previousAllIds.includes(msgId) || previousUnprocessedIds.includes(msgId)),
);
// get all message ids that are part of currentAllIds

for (const msgId of messagesToWitness) {
const msg = ExtendedMessage.fromState(msgState.byId[msgId]);
// The message is witnessed only if it comes from the current lao
if (msg.laoId?.valueOf() === laoId.valueOf()) {
afterProcessingHandler(msg);
} else {
currentAllIds = currentAllIds.filter((id) => id !== msgId);
}

if (laoId !== lastLaoId) {
lastLaoId = laoId;
messagesToWitness = [...messagesToWitness, ...(laoToWitnessableId[laoId.valueOf()] || [])];
laoToWitnessableId[laoId.valueOf()] = [];
}
/*
We keep track of the messages that are not in this LaoId
*/
messagesToWitness
.map((msgId) => ExtendedMessage.fromState(msgState.byId[msgId]))
.forEach((m) => {
if (m.laoId?.equals(laoId)) {
afterProcessingHandler(m);
} else if (m.laoId) {
laoToWitnessableId[m.laoId.valueOf()] = [
...(laoToWitnessableId[m.laoId.valueOf()] || []),
m.message_id.valueOf(),
];
}
});
};
};

0 comments on commit 77daa26

Please sign in to comment.