integrate core codes

This commit is contained in:
Alireza Ahmadi
2024-12-16 00:12:09 +01:00
parent f1b6c8a131
commit ecd9348a0f
22 changed files with 1528 additions and 424 deletions
+8 -4
View File
@@ -19,18 +19,22 @@ var onlineResources = &onlines{}
type StatsService struct {
}
func (s *StatsService) SaveStats(stats []*model.Stats) error {
var err error
func (s *StatsService) SaveStats() error {
if !corePtr.IsRunning() {
return nil
}
stats := corePtr.GetInstance().ConnTracker().GetStats()
// Reset onlines
onlineResources.Inbound = nil
onlineResources.Outbound = nil
onlineResources.User = nil
if len(stats) == 0 {
if len(*stats) == 0 {
return nil
}
var err error
db := database.GetDB()
tx := db.Begin()
defer func() {
@@ -41,7 +45,7 @@ func (s *StatsService) SaveStats(stats []*model.Stats) error {
}
}()
for _, stat := range stats {
for _, stat := range *stats {
if stat.Resource == "user" {
if stat.Direction {
err = tx.Model(model.Client{}).Where("name = ?", stat.Tag).