Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
1073317a
Commit
1073317a
authored
Jan 12, 2026
by
yangjianbo
Browse files
fix(仪表盘): 增加对数据库驱动和仓储实例的有效性检查
parent
839ab37d
Changes
2
Hide whitespace changes
Inline
Side-by-side
backend/internal/repository/dashboard_aggregation_repo.go
View file @
1073317a
...
...
@@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"log"
"strings"
"time"
...
...
@@ -17,6 +18,13 @@ type dashboardAggregationRepository struct {
// NewDashboardAggregationRepository 创建仪表盘预聚合仓储。
func
NewDashboardAggregationRepository
(
sqlDB
*
sql
.
DB
)
service
.
DashboardAggregationRepository
{
if
sqlDB
==
nil
{
return
nil
}
if
!
isPostgresDriver
(
sqlDB
)
{
log
.
Printf
(
"[DashboardAggregation] 检测到非 PostgreSQL 驱动,已自动禁用预聚合"
)
return
nil
}
return
newDashboardAggregationRepositoryWithSQL
(
sqlDB
)
}
...
...
@@ -24,6 +32,14 @@ func newDashboardAggregationRepositoryWithSQL(sqlq sqlExecutor) *dashboardAggreg
return
&
dashboardAggregationRepository
{
sql
:
sqlq
}
}
func
isPostgresDriver
(
db
*
sql
.
DB
)
bool
{
if
db
==
nil
{
return
false
}
_
,
ok
:=
db
.
Driver
()
.
(
*
pq
.
Driver
)
return
ok
}
func
(
r
*
dashboardAggregationRepository
)
AggregateRange
(
ctx
context
.
Context
,
start
,
end
time
.
Time
)
error
{
startUTC
:=
start
.
UTC
()
endUTC
:=
end
.
UTC
()
...
...
backend/internal/service/dashboard_service.go
View file @
1073317a
...
...
@@ -85,6 +85,9 @@ func NewDashboardService(usageRepo UsageLogRepository, aggRepo DashboardAggregat
aggUsageDays
=
cfg
.
DashboardAgg
.
Retention
.
UsageLogsDays
}
}
if
aggRepo
==
nil
{
aggEnabled
=
false
}
return
&
DashboardService
{
usageRepo
:
usageRepo
,
aggRepo
:
aggRepo
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment