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
+17
View File
@@ -1802,6 +1802,23 @@ func (s *InboundService) GetInbound(id int) (*model.Inbound, error) {
return inbound, nil
}
// GetInboundRemarks returns the remarks of the given inbounds keyed by id
// without loading their settings; ids that do not exist are absent.
func (s *InboundService) GetInboundRemarks(ids []int) (map[int]string, error) {
db := database.GetDB()
remarks := make(map[int]string, len(ids))
for _, batch := range chunkInts(ids, sqlInChunk) {
var rows []model.Inbound
if err := db.Select("id", "remark").Where("id IN ?", batch).Find(&rows).Error; err != nil {
return nil, err
}
for i := range rows {
remarks[rows[i].Id] = rows[i].Remark
}
}
return remarks, nil
}
func (s *InboundService) GetInboundDetail(id int) (*model.Inbound, error) {
db := database.GetDB()
inbound := &model.Inbound{}