Skip to content

Commit

Permalink
fix (plg_search_sqlitefts): prevent context expiration if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-kerjean committed Jan 30, 2024
1 parent 029f5ef commit 24e7b5e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
14 changes: 7 additions & 7 deletions server/plugin/plg_backend_s3/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type S3Backend struct {
client *s3.S3
config *aws.Config
params map[string]string
context context.Context
Context context.Context
threadSize int
}

Expand Down Expand Up @@ -89,7 +89,7 @@ func (this S3Backend) Init(params map[string]string, app *App) (IBackend, error)
config: config,
params: params,
client: s3.New(session.New(config)),
context: app.Context,
Context: app.Context,
threadSize: threadSize,
}
return backend, nil
Expand Down Expand Up @@ -200,7 +200,7 @@ func (this S3Backend) Ls(path string) (files []os.FileInfo, err error) {
}
client := s3.New(this.createSession(p.bucket))
err = client.ListObjectsV2PagesWithContext(
this.context,
this.Context,
&s3.ListObjectsV2Input{
Bucket: aws.String(p.bucket),
Prefix: aws.String(p.path),
Expand Down Expand Up @@ -295,7 +295,7 @@ func (this S3Backend) Rm(path string) error {
// CASE 2: remove a folder
jobChan := make(chan S3Path, this.threadSize)
errChan := make(chan error, this.threadSize)
ctx, cancel := context.WithCancel(this.context)
ctx, cancel := context.WithCancel(this.Context)
var wg sync.WaitGroup
for i := 1; i <= this.threadSize; i++ {
wg.Add(1)
Expand All @@ -316,7 +316,7 @@ func (this S3Backend) Rm(path string) error {
}()
}
err := client.ListObjectsV2PagesWithContext(
this.context,
this.Context,
&s3.ListObjectsV2Input{
Bucket: aws.String(p.bucket),
Prefix: aws.String(p.path),
Expand Down Expand Up @@ -387,7 +387,7 @@ func (this S3Backend) Mv(from string, to string) error {
// CASE 3: Rename/Move a folder
jobChan := make(chan []S3Path, this.threadSize)
errChan := make(chan error, this.threadSize)
ctx, cancel := context.WithCancel(this.context)
ctx, cancel := context.WithCancel(this.Context)
var wg sync.WaitGroup
for i := 1; i <= this.threadSize; i++ {
wg.Add(1)
Expand Down Expand Up @@ -427,7 +427,7 @@ func (this S3Backend) Mv(from string, to string) error {
}()
}
err := client.ListObjectsV2PagesWithContext(
this.context,
this.Context,
&s3.ListObjectsV2Input{
Bucket: aws.String(f.bucket),
Prefix: aws.String(f.path),
Expand Down
12 changes: 11 additions & 1 deletion server/plugin/plg_search_sqlitefts/crawlstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package plg_search_sqlitefts

import (
"container/heap"
. "github.com/mickael-kerjean/filestash/server/common"
"context"
"path/filepath"
"reflect"
"sync"

. "github.com/mickael-kerjean/filestash/server/common"
)

var SProc SearchProcess = SearchProcess{
Expand Down Expand Up @@ -60,6 +63,13 @@ func (this *SearchProcess) HintLs(app *App, path string) *SearchIndexer {
}
// instantiate the new indexer
s := NewSearchIndexer(id, app.Backend)
v := reflect.ValueOf(app.Backend).Elem().FieldByName("Context")
if v.IsValid() && v.CanSet() {
// prevent context expiration which is often default as r.Context()
// as we need to make queries outside the scope of a normal http request
v.Set(reflect.ValueOf(context.Background()))
}

heap.Push(&s.FoldersUnknown, &Document{
Type: "directory",
Path: path,
Expand Down

0 comments on commit 24e7b5e

Please sign in to comment.