1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-09-01 23:46:53 +00:00

send event (#490)

* send event

* send event
This commit is contained in:
Xiangyue Cai
2021-09-17 11:07:38 +08:00
committed by GitHub
parent 7f09cff78c
commit 88e917c58e
4 changed files with 75 additions and 18 deletions

View File

@@ -42,6 +42,7 @@ const (
permExpireTime = 7200
virtualRepoExpireTime = 7200
syncAPICleaningIntervalSec = 300
maxObjectPackSize = 1 << 20 // 1MB
)
var (
@@ -473,6 +474,7 @@ func packFSCB(rsp http.ResponseWriter, r *http.Request) *appError {
return &appError{nil, err.Error(), http.StatusBadRequest}
}
var totalSize int
var data bytes.Buffer
for i := 0; i < len(fsIDList); i++ {
if !isObjectIDValid(fsIDList[i]) {
@@ -489,6 +491,11 @@ func packFSCB(rsp http.ResponseWriter, r *http.Request) *appError {
binary.BigEndian.PutUint32(tmpLen, uint32(tmp.Len()))
data.Write(tmpLen)
data.Write(tmp.Bytes())
totalSize += tmp.Len()
if totalSize >= maxObjectPackSize {
break
}
}
rsp.Header().Set("Content-Length", strconv.Itoa(data.Len()))
@@ -1128,6 +1135,13 @@ func publishRepoEvent(rData *repoEventData) {
}
}
func publishUpdateEvent(repoID string, commitID string) {
buf := fmt.Sprintf("repo-update\t%s\t%s", repoID, commitID)
if _, err := rpcclient.Call("publish_event", seafileServerChannelEvent, buf); err != nil {
log.Printf("Failed to publish event: %v", err)
}
}
func removeSyncAPIExpireCache() {
deleteTokens := func(key interface{}, value interface{}) bool {
if info, ok := value.(*tokenInfo); ok {