mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-09-13 05:41:30 +00:00
Add timeout when query from database (#685)
* Add timeout when query from database * Modify DefaultTimeout to DBOpTimeout --------- Co-authored-by: 杨赫然 <heran.yang@seafile.com>
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
@@ -114,14 +116,16 @@ func Notify(msg *Message) {
|
||||
|
||||
func getGroupMembers(group int) map[string]struct{} {
|
||||
query := `SELECT user_name FROM GroupUser WHERE group_id = ?`
|
||||
stmt, err := ccnetDB.Prepare(query)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
defer cancel()
|
||||
stmt, err := ccnetDB.PrepareContext(ctx, query)
|
||||
if err != nil {
|
||||
log.Printf("failed to prepare sql: %s:%v", query, err)
|
||||
return nil
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
rows, err := stmt.Query(group)
|
||||
rows, err := stmt.QueryContext(ctx, group)
|
||||
if err != nil {
|
||||
log.Printf("failed to query sql: %v", err)
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user