mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-02 19:25:05 +03:00
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:
@@ -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{}
|
||||
|
||||
Reference in New Issue
Block a user