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
7a0f7c75
Commit
7a0f7c75
authored
Jul 24, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
分批获取userIds
parent
7f229adb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
4 deletions
+36
-4
user.go
domain/model/user_m/user.go
+20
-4
user_test.go
test/user_test.go
+16
-0
No files found.
domain/model/user_m/user.go
View file @
7a0f7c75
...
@@ -85,12 +85,28 @@ func GetUsersByIds(model *domain.Model, userIds []mysql.ID) ([]User, error) {
...
@@ -85,12 +85,28 @@ func GetUsersByIds(model *domain.Model, userIds []mysql.ID) ([]User, error) {
return
users
,
nil
return
users
,
nil
}
}
// 分批获取userIds
func
GetUserMapByIds
(
model
*
domain
.
Model
,
userIds
[]
mysql
.
ID
)
(
map
[
mysql
.
ID
]
User
,
error
)
{
func
GetUserMapByIds
(
model
*
domain
.
Model
,
userIds
[]
mysql
.
ID
)
(
map
[
mysql
.
ID
]
User
,
error
)
{
rows
,
err
:=
GetUsersByIds
(
model
,
userIds
)
result
:=
make
(
map
[
mysql
.
ID
]
User
,
0
)
end
:=
500
if
end
>
len
(
userIds
)
{
end
=
len
(
userIds
)
}
var
rows
[]
User
start
:=
0
for
end
<=
len
(
userIds
)
{
if
end
>
len
(
userIds
)
{
end
=
len
(
userIds
)
}
tmp
,
err
:=
GetUsersByIds
(
model
,
userIds
[
start
:
end
])
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
result
,
err
}
else
{
rows
=
append
(
rows
,
tmp
...
)
}
start
+=
500
end
+=
500
}
}
result
:=
make
(
map
[
mysql
.
ID
]
User
,
0
)
for
_
,
i
:=
range
rows
{
for
_
,
i
:=
range
rows
{
result
[
i
.
ID
]
=
i
result
[
i
.
ID
]
=
i
}
}
...
...
test/user_test.go
0 → 100644
View file @
7a0f7c75
package
test
import
(
"git.hilo.cn/hilo-common/domain"
"hilo-group/domain/model/user_m"
"testing"
)
func
TestGetUserMap
(
t
*
testing
.
T
)
{
var
userIds
[]
uint64
for
i
:=
0
;
i
<
10502
;
i
++
{
userIds
=
append
(
userIds
,
7642
)
}
res
,
err
:=
user_m
.
GetUserMapByIds
(
domain
.
CreateModelNil
(),
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