From fb1524803024521c61865c75a48906df48873a58 Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Thu, 13 Apr 2023 16:31:35 +0200 Subject: [PATCH] [migration] Remove Orphaned Traffics --- web/service/inbound.go | 11 +++++++++++ web/service/xray.go | 1 + 2 files changed, 12 insertions(+) diff --git a/web/service/inbound.go b/web/service/inbound.go index c40cf004..90a99a52 100644 --- a/web/service/inbound.go +++ b/web/service/inbound.go @@ -489,6 +489,17 @@ func (s *InboundService) DisableInvalidClients() (int64, error) { count := result.RowsAffected return count, err } +func (s *InboundService) RemoveOrphanedTraffics() { + db := database.GetDB() + db.Exec(` + DELETE FROM client_traffics + WHERE email NOT IN ( + SELECT JSON_EXTRACT(client.value, '$.email') + FROM inbounds, + JSON_EACH(JSON_EXTRACT(inbounds.settings, '$.clients')) AS client + ) + `) +} func (s *InboundService) AddClientStat(inboundId int, client *model.Client) error { db := database.GetDB() diff --git a/web/service/xray.go b/web/service/xray.go index 6e63d2d1..9c23f7a4 100644 --- a/web/service/xray.go +++ b/web/service/xray.go @@ -69,6 +69,7 @@ func (s *XrayService) GetXrayConfig() (*xray.Config, error) { } s.inboundService.DisableInvalidClients() + s.inboundService.RemoveOrphanedTraffics() inbounds, err := s.inboundService.GetAllInbounds() if err != nil {