mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-22 18:25:47 +08:00
feat: fix tableNamePrefix doesn't work bug in /get-dashboard API (#3572)
This commit is contained in:
parent
b1b6ebe692
commit
c0ec73dfd3
@ -17,6 +17,8 @@ package object
|
|||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/casdoor/casdoor/conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DashboardDateItem struct {
|
type DashboardDateItem struct {
|
||||||
@ -40,11 +42,12 @@ func GetDashboard(owner string) (*map[string][]int64, error) {
|
|||||||
time30day := time.Now().AddDate(0, 0, -30)
|
time30day := time.Now().AddDate(0, 0, -30)
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
var err error
|
var err error
|
||||||
|
tableNamePrefix := conf.GetConfigString("tableNamePrefix")
|
||||||
wg.Add(len(tableNames))
|
wg.Add(len(tableNames))
|
||||||
ch := make(chan error, len(tableNames))
|
ch := make(chan error, len(tableNames))
|
||||||
for _, tableName := range tableNames {
|
for _, tableName := range tableNames {
|
||||||
dashboard[tableName+"Counts"] = make([]int64, 31)
|
dashboard[tableName+"Counts"] = make([]int64, 31)
|
||||||
tableName := tableName
|
tableFullName := tableNamePrefix + tableName
|
||||||
go func(ch chan error) {
|
go func(ch chan error) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
dashboardDateItems := []DashboardDateItem{}
|
dashboardDateItems := []DashboardDateItem{}
|
||||||
@ -58,16 +61,16 @@ func GetDashboard(owner string) (*map[string][]int64, error) {
|
|||||||
dbQueryBefore = dbQueryBefore.And("owner = ?", owner)
|
dbQueryBefore = dbQueryBefore.And("owner = ?", owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
if countResult, err = dbQueryBefore.And("created_time < ?", time30day).Table(tableName).Count(); err != nil {
|
if countResult, err = dbQueryBefore.And("created_time < ?", time30day).Table(tableFullName).Count(); err != nil {
|
||||||
ch <- err
|
ch <- err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = dbQueryAfter.And("created_time >= ?", time30day).Table(tableName).Find(&dashboardDateItems); err != nil {
|
if err = dbQueryAfter.And("created_time >= ?", time30day).Table(tableFullName).Find(&dashboardDateItems); err != nil {
|
||||||
ch <- err
|
ch <- err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dashboardMap.Store(tableName, DashboardMapItem{
|
dashboardMap.Store(tableFullName, DashboardMapItem{
|
||||||
dashboardDateItems: dashboardDateItems,
|
dashboardDateItems: dashboardDateItems,
|
||||||
itemCount: countResult,
|
itemCount: countResult,
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user