Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a9ec62ee
authored
Jun 14, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🐛
fix(ability, channel): standardize boolean value handling across database queries
parent
4371717c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
15 deletions
+13
-15
model/ability.go
+4
-12
model/channel.go
+2
-2
model/main.go
+7
-1
No files found.
model/ability.go
View file @
a9ec62ee
...
...
@@ -42,15 +42,11 @@ func GetAllEnableAbilities() []Ability {
}
func
getPriority
(
group
string
,
model
string
,
retry
int
)
(
int
,
error
)
{
trueVal
:=
"1"
if
common
.
UsingPostgreSQL
{
trueVal
=
"true"
}
var
priorities
[]
int
err
:=
DB
.
Model
(
&
Ability
{})
.
Select
(
"DISTINCT(priority)"
)
.
Where
(
commonGroupCol
+
" = ? and model = ? and enabled =
"
+
trueVal
,
group
,
mode
l
)
.
Where
(
commonGroupCol
+
" = ? and model = ? and enabled =
?"
,
group
,
model
,
commonTrueVa
l
)
.
Order
(
"priority DESC"
)
.
// 按优先级降序排序
Pluck
(
"priority"
,
&
priorities
)
.
Error
// Pluck用于将查询的结果直接扫描到一个切片中
...
...
@@ -76,18 +72,14 @@ func getPriority(group string, model string, retry int) (int, error) {
}
func
getChannelQuery
(
group
string
,
model
string
,
retry
int
)
*
gorm
.
DB
{
trueVal
:=
"1"
if
common
.
UsingPostgreSQL
{
trueVal
=
"true"
}
maxPrioritySubQuery
:=
DB
.
Model
(
&
Ability
{})
.
Select
(
"MAX(priority)"
)
.
Where
(
commonGroupCol
+
" = ? and model = ? and enabled = "
+
trueVal
,
group
,
model
)
channelQuery
:=
DB
.
Where
(
commonGroupCol
+
" = ? and model = ? and enabled = "
+
trueVal
+
" and priority = (?)"
,
group
,
model
,
maxPrioritySubQuery
)
maxPrioritySubQuery
:=
DB
.
Model
(
&
Ability
{})
.
Select
(
"MAX(priority)"
)
.
Where
(
commonGroupCol
+
" = ? and model = ? and enabled = ?"
,
group
,
model
,
commonTrueVal
)
channelQuery
:=
DB
.
Where
(
commonGroupCol
+
" = ? and model = ? and enabled = ? and priority = (?)"
,
group
,
model
,
commonTrueVal
,
maxPrioritySubQuery
)
if
retry
!=
0
{
priority
,
err
:=
getPriority
(
group
,
model
,
retry
)
if
err
!=
nil
{
common
.
SysError
(
fmt
.
Sprintf
(
"Get priority failed: %s"
,
err
.
Error
()))
}
else
{
channelQuery
=
DB
.
Where
(
commonGroupCol
+
" = ? and model = ? and enabled =
"
+
trueVal
+
" and priority = ?"
,
group
,
mode
l
,
priority
)
channelQuery
=
DB
.
Where
(
commonGroupCol
+
" = ? and model = ? and enabled =
? and priority = ?"
,
group
,
model
,
commonTrueVa
l
,
priority
)
}
}
...
...
model/channel.go
View file @
a9ec62ee
...
...
@@ -145,7 +145,7 @@ func SearchChannels(keyword string, group string, model string, idSort bool) ([]
}
// 构造基础查询
baseQuery
:=
DB
.
Model
(
&
Channel
{})
.
Omit
(
commonKeyCol
)
baseQuery
:=
DB
.
Model
(
&
Channel
{})
.
Omit
(
"key"
)
// 构造WHERE子句
var
whereClause
string
...
...
@@ -478,7 +478,7 @@ func SearchTags(keyword string, group string, model string, idSort bool) ([]*str
}
// 构造基础查询
baseQuery
:=
DB
.
Model
(
&
Channel
{})
.
Omit
(
commonKeyCol
)
baseQuery
:=
DB
.
Model
(
&
Channel
{})
.
Omit
(
"key"
)
// 构造WHERE子句
var
whereClause
string
...
...
model/main.go
View file @
a9ec62ee
...
...
@@ -18,6 +18,8 @@ import (
var
commonGroupCol
string
var
commonKeyCol
string
var
commonTrueVal
string
var
commonFalseVal
string
var
logKeyCol
string
var
logGroupCol
string
...
...
@@ -27,11 +29,15 @@ func initCol() {
if
common
.
UsingPostgreSQL
{
commonGroupCol
=
`"group"`
commonKeyCol
=
`"key"`
commonTrueVal
=
"true"
commonFalseVal
=
"false"
}
else
{
commonGroupCol
=
"`group`"
commonKeyCol
=
"`key`"
commonTrueVal
=
"1"
commonFalseVal
=
"0"
}
if
DB
!=
LOG_DB
{
if
os
.
Getenv
(
"LOG_SQL_DSN"
)
!=
""
{
switch
common
.
LogSqlType
{
case
common
.
DatabaseTypePostgreSQL
:
logGroupCol
=
`"group"`
...
...
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