mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-05 01:11:54 +08:00
修复查询网站日流量统计时可能不兼容MySQL8的问题
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -513,7 +514,8 @@ func (this *ServerDailyStatDAO) FindStatsWithDay(tx *dbs.Tx, serverId int64, day
|
|||||||
Result("SUM(bytes) AS bytes", "SUM(cachedBytes) AS cachedBytes", "SUM(countRequests) AS countRequests", "SUM(countCachedRequests) AS countCachedRequests", "SUM(countAttackRequests) AS countAttackRequests", "SUM(attackBytes) AS attackBytes", "day", "timeFrom", "MIN(timeTo) AS timeTo").
|
Result("SUM(bytes) AS bytes", "SUM(cachedBytes) AS cachedBytes", "SUM(countRequests) AS countRequests", "SUM(countCachedRequests) AS countCachedRequests", "SUM(countAttackRequests) AS countAttackRequests", "SUM(attackBytes) AS attackBytes", "day", "timeFrom", "MIN(timeTo) AS timeTo").
|
||||||
Attr("serverId", serverId).
|
Attr("serverId", serverId).
|
||||||
Attr("day", day).
|
Attr("day", day).
|
||||||
Group("day").Group("timeFrom", dbs.QueryOrderDesc)
|
Group("day").
|
||||||
|
Group("timeFrom")
|
||||||
|
|
||||||
if len(timeFrom) > 0 {
|
if len(timeFrom) > 0 {
|
||||||
query.Gte("timeFrom", timeFrom)
|
query.Gte("timeFrom", timeFrom)
|
||||||
@@ -530,6 +532,11 @@ func (this *ServerDailyStatDAO) FindStatsWithDay(tx *dbs.Tx, serverId int64, day
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sort results
|
||||||
|
sort.Slice(result, func(i, j int) bool {
|
||||||
|
return result[i].TimeFrom < result[j].TimeFrom
|
||||||
|
})
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -140,6 +140,6 @@ func TestServerDailyStatDAO_FindStatsWithDay(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
for _, stat := range stats {
|
for _, stat := range stats {
|
||||||
t.Log(stat.TimeFrom, stat.TimeTo, stat.Bytes)
|
t.Log(stat.Day, stat.TimeFrom, stat.TimeTo, stat.Bytes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user