From 33edd2ceaf6885d38d68aba8c141aa817179a1f3 Mon Sep 17 00:00:00 2001 From: LDA Date: Tue, 3 Dec 2024 15:57:05 +0100 Subject: [PATCH] [MOD] Do NOT do unnecessary notifications I should move notifying users into some sort of background task. It is not particularly necessary to send events, and essentially slows down the requester thread doing something that's not really sending an event. It could also scale terribly in rooms where there exists a lot of local users, with every one of them having possibly at least hundreds of sync tokens. --- src/Room/V1/Send.c | 7 ------- src/User.c | 4 +++- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Room/V1/Send.c b/src/Room/V1/Send.c index b5b4dca..630178d 100644 --- a/src/Room/V1/Send.c +++ b/src/Room/V1/Send.c @@ -338,13 +338,6 @@ RoomAddEventV1(Room *room, PduV1 pdu, PduV1Status status) /* If we have a membership change, then add it to the * proper table. */ - { - CommonID *id = UserIdParse(pdu.sender, NULL); - User *user = UserLockID(room->db, id); - UserPushEvent(user, pdu_json); - UserUnlock(user); - UserIdFree(id); - } if (relates_to && RelationFromJson(relates_to, &rel, &errp)) { DbRef *relate = DbLock( diff --git a/src/User.c b/src/User.c index 6248160..9aeab69 100644 --- a/src/User.c +++ b/src/User.c @@ -1387,6 +1387,8 @@ UserPushEvent(User *user, HashMap *event) UserPushJoinSync(user, roomId); + /* TODO: In some very fun cases, this loop could be cosmically slow. + * Especially in the scale of 1.5k sync tokens. It can happen. */ entries = DbList(user->db, 3, "users", user->name, "sync"); for (i = 0; i < ArraySize(entries); i++) { @@ -1859,7 +1861,7 @@ UserIsSyncOld(User *user, char *token) dt = UtilTsMillis() - JsonValueAsInteger(HashMapGet(map, "creation")); DbUnlock(user->db, ref); - return dt > (3 * 24 * 60 * 60 * 1000); /* Three days of timeout. */ + return dt > (3 * 60 * 60 * 1000); /* Three hours of timeout. */ } bool UserSyncExists(User *user, char *sync)