perf(tgbot): stop loading the whole inbound per client in usage listings

Listing a Telegram account's clients ran CheckIsEnabledByEmail and
describeAttachedInbounds for every client, and both loaded and parsed
the client's entire inbound, so one message cost the number of clients
times the size of their inbound's settings.

CheckIsEnabledByEmail now reads the client's own record first, keeping
the inbound parse only for legacy clients never normalized into the
clients table, and describeAttachedInbounds takes every remark in one
query without loading any settings.
This commit is contained in:
MHSanaei
2026-11-01 09:14:43 +01:00
parent 7163c6e521
commit efaa73db3a
4 changed files with 87 additions and 6 deletions
@@ -1351,6 +1351,12 @@ func (s *ClientService) SetClientTelegramUserID(inboundSvc *InboundService, traf
}
func (s *ClientService) CheckIsEnabledByEmail(inboundSvc *InboundService, clientEmail string) (bool, error) {
// The client's own row answers without loading and parsing its whole
// inbound; legacy clients never normalized into `clients` fall through.
if rec, rErr := s.GetRecordByEmail(nil, clientEmail); rErr == nil && rec != nil {
return rec.Enable, nil
}
_, inbound, err := inboundSvc.GetClientInboundByEmail(clientEmail)
if err != nil {
return false, err