Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄成意
/
go_sku_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
778077da
authored
Nov 04, 2025
by
hcy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
并发问题
parent
82dff93b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
5 deletions
controller/sku_controller.go
service/service_ly.go
controller/sku_controller.go
View file @
778077da
...
...
@@ -121,7 +121,9 @@ func CommonController(ctx *gin.Context) map[string]interface{} {
//wgcount := 0 //当前线程数
temp
:=
make
(
map
[
string
]
interface
{})
//最后输出计算结果
sd
:=
0
for
_
,
goodsId
:=
range
goodsIdArr
{
sd
+=
1
//if len(goodsIdArr) > 100 {
// common.Output(ctx, 1001, "查询型号ID不得超过100个", "")
// return nil
...
...
@@ -163,11 +165,11 @@ func CommonController(ctx *gin.Context) map[string]interface{} {
}
// 启动协程,传递独立的 context 和参数,而不是 gin.Context
go
func
(
ctx
context
.
Context
,
params
service
.
RequestParams
,
skuStr
,
goodsId
,
spuStr
string
,
ch
chan
sync
.
Map
)
{
go
func
(
ctx
context
.
Context
,
params
service
.
RequestParams
,
skuStr
,
goodsId
,
spuStr
string
,
ch
chan
sync
.
Map
,
tag
int
)
{
//defer wg.Done()
defer
func
()
{
<-
ch
}()
lyService
.
LyGoodsDetail
(
ctx
,
params
,
skuStr
,
goodsId
,
spuStr
,
ch
)
}(
ctx
,
requestParams
,
skuStr
,
goodsId
,
redisLySpuArr
[
spuId
],
ch
)
lyService
.
LyGoodsDetail
(
ctx
,
params
,
skuStr
,
goodsId
,
spuStr
,
ch
,
tag
)
}(
ctx
,
requestParams
,
skuStr
,
goodsId
,
redisLySpuArr
[
spuId
],
ch
,
sd
)
//wg.Add(1)
// wgcount += 1
...
...
service/service_ly.go
View file @
778077da
...
...
@@ -37,7 +37,7 @@ type Power struct {
联营数据详情
使用 context.Context 控制协程生命周期,避免 gin.Context 在协程中的并发问题
*/
func
(
ls
*
LyService
)
LyGoodsDetail
(
ctx
context
.
Context
,
params
RequestParams
,
skuStr
,
goodsId
,
spuStr
string
,
ch
chan
sync
.
Map
)
{
func
(
ls
*
LyService
)
LyGoodsDetail
(
ctx
context
.
Context
,
params
RequestParams
,
skuStr
,
goodsId
,
spuStr
string
,
ch
chan
sync
.
Map
,
tag
int
)
{
start_time
:=
gconv
.
String
(
time
.
Now
()
.
UnixMilli
())
redisConn
:=
gredis
.
Conn
(
"search_r"
)
...
...
@@ -275,7 +275,7 @@ func (ls *LyService) LyGoodsDetail(ctx context.Context, params RequestParams, sk
//退出通道
ch
<-
GoodsRes
println
(
"-----goodsId:"
+
goodsId
+
"--start_time:"
+
start_time
+
" ---end_time:"
+
gconv
.
String
(
time
.
Now
()
.
UnixMilli
()))
println
(
"---
tag:"
+
gconv
.
String
(
tag
)
+
"---
--goodsId:"
+
goodsId
+
"--start_time:"
+
start_time
+
" ---end_time:"
+
gconv
.
String
(
time
.
Now
()
.
UnixMilli
()))
}
// 获取活动
...
...
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