1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-09-03 08:24:27 +00:00

Reuse zlib ReadCloser and add timeout for get fs id list (#508)

* Reuse zlib ReadCloser and add timeout for get fs id list

* Reuse zlib reader

* Get seafile and seafdir with zlib reader

Co-authored-by: 杨赫然 <heran.yang@seafile.com>

Use json-iterator/go to parse fs objects (#510)

Co-authored-by: 杨赫然 <heran.yang@seafile.com>

Add cache for seafdir (#511)

* Add cache for seafile and seafdir

* Add ttl for fs cache

* Use MB unit and add a comment

Co-authored-by: 杨赫然 <heran.yang@seafile.com>

Close object after reading finished (#512)

Co-authored-by: 杨赫然 <heran.yang@seafile.com>
This commit is contained in:
feiniks
2022-11-10 16:17:34 +08:00
committed by 杨赫然
parent 04350f2b99
commit df78d10ec1
9 changed files with 310 additions and 44 deletions

View File

@@ -3,6 +3,7 @@ package diff
import (
"context"
"fmt"
"io"
"path/filepath"
"strings"
@@ -25,6 +26,7 @@ type DiffOptions struct {
RepoID string
Ctx context.Context
Data interface{}
Reader io.ReadCloser
}
type diffData struct {
@@ -33,6 +35,10 @@ type diffData struct {
}
func DiffTrees(roots []string, opt *DiffOptions) error {
reader := fsmgr.GetOneZlibReader()
defer fsmgr.ReturnOneZlibReader(reader)
opt.Reader = reader
n := len(roots)
if n != 2 && n != 3 {
err := fmt.Errorf("the number of commit trees is illegal")
@@ -40,7 +46,7 @@ func DiffTrees(roots []string, opt *DiffOptions) error {
}
trees := make([]*fsmgr.SeafDir, n)
for i := 0; i < n; i++ {
root, err := fsmgr.GetSeafdir(opt.RepoID, roots[i])
root, err := fsmgr.GetSeafdirWithZlibReader(opt.RepoID, roots[i], opt.Reader)
if err != nil {
err := fmt.Errorf("Failed to find dir %s:%s", opt.RepoID, roots[i])
return err
@@ -165,7 +171,7 @@ func diffDirectories(baseDir string, dents []*fsmgr.SeafDirent, opt *DiffOptions
var dirName string
for i := 0; i < n; i++ {
if dents[i] != nil && fsmgr.IsDir(dents[i].Mode) {
dir, err := fsmgr.GetSeafdir(opt.RepoID, dents[i].ID)
dir, err := fsmgr.GetSeafdirWithZlibReader(opt.RepoID, dents[i].ID, opt.Reader)
if err != nil {
err := fmt.Errorf("Failed to find dir %s:%s", opt.RepoID, dents[i].ID)
return err