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:
@@ -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
|
||||
|
Reference in New Issue
Block a user