mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
🎨 Concurrency control when requesting the kernel API https://github.com/siyuan-note/siyuan/issues/9939
This commit is contained in:
parent
3c52ad491e
commit
b5494e9af7
2 changed files with 21 additions and 0 deletions
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
|
|
@ -317,3 +318,22 @@ func Recover(c *gin.Context) {
|
||||||
|
|
||||||
c.Next()
|
c.Next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
requestingLock = sync.Mutex{}
|
||||||
|
requesting = map[string]*sync.Mutex{}
|
||||||
|
)
|
||||||
|
|
||||||
|
func ControlConcurrency(c *gin.Context) {
|
||||||
|
requestingLock.Lock()
|
||||||
|
mutex := requesting[c.Request.URL.Path]
|
||||||
|
if nil == mutex {
|
||||||
|
mutex = &sync.Mutex{}
|
||||||
|
requesting[c.Request.URL.Path] = mutex
|
||||||
|
}
|
||||||
|
requestingLock.Unlock()
|
||||||
|
|
||||||
|
mutex.Lock()
|
||||||
|
c.Next()
|
||||||
|
mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ func Serve(fastMode bool) {
|
||||||
ginServer := gin.New()
|
ginServer := gin.New()
|
||||||
ginServer.MaxMultipartMemory = 1024 * 1024 * 32 // 插入较大的资源文件时内存占用较大 https://github.com/siyuan-note/siyuan/issues/5023
|
ginServer.MaxMultipartMemory = 1024 * 1024 * 32 // 插入较大的资源文件时内存占用较大 https://github.com/siyuan-note/siyuan/issues/5023
|
||||||
ginServer.Use(
|
ginServer.Use(
|
||||||
|
model.ControlConcurrency, // 请求串行化 Concurrency control when requesting the kernel API https://github.com/siyuan-note/siyuan/issues/9939
|
||||||
model.Timing,
|
model.Timing,
|
||||||
model.Recover,
|
model.Recover,
|
||||||
corsMiddleware(), // 后端服务支持 CORS 预检请求验证 https://github.com/siyuan-note/siyuan/pull/5593
|
corsMiddleware(), // 后端服务支持 CORS 预检请求验证 https://github.com/siyuan-note/siyuan/pull/5593
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue