🎨 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"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
|
@ -317,3 +318,22 @@ func Recover(c *gin.Context) {
|
|||
|
||||
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.MaxMultipartMemory = 1024 * 1024 * 32 // 插入较大的资源文件时内存占用较大 https://github.com/siyuan-note/siyuan/issues/5023
|
||||
ginServer.Use(
|
||||
model.ControlConcurrency, // 请求串行化 Concurrency control when requesting the kernel API https://github.com/siyuan-note/siyuan/issues/9939
|
||||
model.Timing,
|
||||
model.Recover,
|
||||
corsMiddleware(), // 后端服务支持 CORS 预检请求验证 https://github.com/siyuan-note/siyuan/pull/5593
|
||||
|
|
Loading…
Add table
Reference in a new issue