- 修改genFakeID1,不会生成重复的ID
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi"
|
||||
@@ -235,9 +236,25 @@ func IsSkuSpecial(specQuality float32, specUnit string) bool {
|
||||
return int(specQuality) == model.SpecialSpecQuality && (specUnit == model.SpecialSpecUnit || specUnit == model.SpecialSpecUnit2)
|
||||
}
|
||||
|
||||
var lastFakeID int64
|
||||
var lastFakeIDMutex sync.RWMutex
|
||||
|
||||
// 生成一个不重复的临时ID
|
||||
func genFakeID1() int64 {
|
||||
return time.Now().UnixNano() / 1000000
|
||||
for {
|
||||
fakeID := time.Now().UnixNano() / 1000
|
||||
lastFakeIDMutex.RLock()
|
||||
if fakeID == lastFakeID {
|
||||
lastFakeIDMutex.RUnlock()
|
||||
time.Sleep(1 * time.Microsecond)
|
||||
} else {
|
||||
lastFakeIDMutex.RUnlock()
|
||||
lastFakeIDMutex.Lock()
|
||||
defer lastFakeIDMutex.Unlock()
|
||||
lastFakeID = fakeID
|
||||
return fakeID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 这个用于没有打开远程同步时的假同步,生成ID使用
|
||||
|
||||
Reference in New Issue
Block a user