GNUWeeb / GNUWeebBot

High-performance bot Telegram, running on Linux environment, written in C.
GNU General Public License v2.0
13 stars 8 forks source link

[core] Create admin cache to reduce privilege check latency #34

Open ammarfaizi2 opened 3 years ago

ammarfaizi2 commented 3 years ago

Calling getChatAdministrators() every time privilege check is done is too expensive w.r.t. latency.

Workaround

Pseudo Code

if (message_count % N == 0) {
  updateAdminCache();
}

/*
 * Privilege check function
 */
bool checkPrivileged(uint64_t user_id, int64_t group_id) {
   if (checkPrivilegeFromCache(user_id, group_id)) 
      return true;
   updateAdminCache();
   return checkPrivilegeFromCache(user_id, group_id);
}