🎨 Concurrency control when requesting the kernel API https://github.com/siyuan-note/siyuan/issues/9939

This commit is contained in:
Daniel 2023-12-22 10:00:40 +08:00
parent 3c52ad491e
commit b5494e9af7
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 21 additions and 0 deletions

View file

@ -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()
}