Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-group
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-group
Commits
dec0f08d
You need to sign in or sign up before continuing.
Commit
dec0f08d
authored
Jul 24, 2023
by
iamhujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
分批获取
parent
512aa032
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
4 deletions
+34
-4
vip.go
domain/model/user_m/vip.go
+25
-4
user_test.go
test/user_test.go
+9
-0
No files found.
domain/model/user_m/vip.go
View file @
dec0f08d
...
...
@@ -2,6 +2,7 @@ package user_m
import
(
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
"gorm.io/gorm/clause"
...
...
@@ -59,14 +60,34 @@ func GetVip(db *gorm.DB, userId uint64) (*UserVip, error) {
return
nil
,
nil
}
// 分批获取
func
BatchGetVips
(
userIds
[]
uint64
)
(
map
[
uint64
]
*
int64
,
error
)
{
result
:=
make
(
map
[
uint64
]
*
int64
,
0
)
rows
:=
make
([]
UserVip
,
0
)
err
:=
mysql
.
Db
.
Where
(
"user_id IN ?"
,
userIds
)
.
Find
(
&
rows
)
.
Error
if
err
!=
nil
{
return
nil
,
err
end
:=
500
if
end
>
len
(
userIds
)
{
end
=
len
(
userIds
)
}
start
:=
0
for
end
<=
len
(
userIds
)
{
if
end
>
len
(
userIds
)
{
end
=
len
(
userIds
)
}
tmp
:=
make
([]
UserVip
,
0
)
err
:=
mysql
.
Db
.
Where
(
"user_id IN ?"
,
userIds
)
.
Find
(
&
tmp
)
.
Error
if
err
!=
nil
{
return
nil
,
err
}
if
err
!=
nil
{
return
result
,
err
}
else
{
rows
=
append
(
rows
,
tmp
...
)
}
start
+=
500
end
+=
500
mylogrus
.
MyLog
.
Infof
(
"BatchGetVips start:%v-end:%v"
,
start
,
end
)
}
result
:=
make
(
map
[
uint64
]
*
int64
,
0
)
for
_
,
i
:=
range
userIds
{
result
[
i
]
=
nil
}
...
...
test/user_test.go
View file @
dec0f08d
...
...
@@ -14,3 +14,12 @@ func TestGetUserMap(t *testing.T) {
res
,
err
:=
user_m
.
GetUserMapByIds
(
domain
.
CreateModelNil
(),
userIds
)
t
.
Logf
(
"%v-%v"
,
res
,
err
)
}
func
TestGetUserVipMap
(
t
*
testing
.
T
)
{
var
userIds
[]
uint64
for
i
:=
0
;
i
<
15000
;
i
++
{
userIds
=
append
(
userIds
,
7642
)
}
res
,
err
:=
user_m
.
BatchGetVips
(
userIds
)
t
.
Logf
(
"%v-%v"
,
res
,
err
)
}
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