Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMHSanaei <ho3ein.sanaei@gmail.com>2023-04-13 18:15:18 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2023-04-13 18:15:18 +0300
commitc6b59f1ee3ad4470a15aac2a6f2b0f62be260788 (patch)
tree4f8453b514ff491f05e16b04ae9dba2c616c197b
parentb40759fe186151d050eac3995c9452e169170478 (diff)
[migration] Remove Orphaned Traffics
Co-Authored-By: Alireza Ahmadi <alireza7@gmail.com>
-rw-r--r--web/service/inbound.go11
-rw-r--r--web/service/xray.go1
2 files changed, 12 insertions, 0 deletions
diff --git a/web/service/inbound.go b/web/service/inbound.go
index f857bfaa..b7eb6789 100644
--- a/web/service/inbound.go
+++ b/web/service/inbound.go
@@ -507,6 +507,17 @@ func (s *InboundService) DisableInvalidInbounds() (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) DisableInvalidClients() (int64, error) {
db := database.GetDB()
now := time.Now().Unix() * 1000
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 {