Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c10d212

Browse files
committed
今早释放锁
1 parent 4593ccc commit c10d212

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

websites/code2/studygolang/src/http/controller/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (SearchController) Search(ctx echo.Context) error {
3030
"f": field,
3131
}
3232
if err == nil {
33-
uri := "/search?q=" + q + "&f=" + field
33+
uri := "/search?q=" + q + "&f=" + field + "&"
3434
paginator := logic.NewPaginatorWithPerPage(p, rows)
3535
data["pageHtml"] = paginator.SetTotal(int64(respBody.NumFound)).GetPageHtml(uri)
3636
}

websites/code2/studygolang/src/logic/book.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ func (this *book) AddUser(user, serverId int) *UserData {
9292
var userData *UserData
9393
var ok bool
9494
this.rwMutex.Lock()
95-
defer this.rwMutex.Unlock()
9695
if userData, ok = this.users[user]; ok {
96+
this.rwMutex.Unlock()
97+
9798
userData.InitMessageQueue(serverId)
9899
userData.onlineDuartion += time.Now().Sub(userData.lastAccessTime)
99100
userData.lastAccessTime = time.Now()
@@ -103,12 +104,15 @@ func (this *book) AddUser(user, serverId int) *UserData {
103104
lastAccessTime: time.Now(),
104105
}
105106
this.users[user] = userData
107+
length := len(this.users)
108+
109+
this.rwMutex.Unlock()
106110

107-
onlineInfo := map[string]int{"online": len(this.users)}
111+
onlineInfo := map[string]int{"online": length}
108112
// 在线人数超过历史最高
109-
if len(this.users) > MaxOnlineNum() {
113+
if length > MaxOnlineNum() {
110114
maxRwMu.Lock()
111-
maxOnlineNum = len(this.users)
115+
maxOnlineNum = length
112116
onlineInfo["maxonline"] = maxOnlineNum
113117
maxRwMu.Unlock()
114118
saveMaxOnlineNum()

0 commit comments

Comments
 (0)