Skip to content

Commit

Permalink
Merge pull request #550 from fairDataSociety/saveFeedsInLRU.1
Browse files Browse the repository at this point in the history
cacheSize and cacheTTL
  • Loading branch information
asabya authored Oct 13, 2023
2 parents 06a68d4 + fb198ed commit ff3a4ec
Show file tree
Hide file tree
Showing 62 changed files with 236 additions and 209 deletions.
4 changes: 2 additions & 2 deletions cmd/dfs/cmd/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestApis(t *testing.T) {
mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger)
ens := mock2.NewMockNamespaceManager()

users := user.NewUsers(mockClient, ens, logger)
users := user.NewUsers(mockClient, ens, 500, 0, logger)
dfsApi := dfs.NewMockDfsAPI(mockClient, users, logger)
handler = api.NewMockHandler(dfsApi, logger, []string{"http://localhost:3000"})
defer handler.Close()
Expand All @@ -77,7 +77,7 @@ func TestApis(t *testing.T) {
}
}()

// wait 10 seconds for the server to start
// wait for the server to start
<-time.After(time.Second * 3)
t.Run("login-fail-test", func(t *testing.T) {
c := http.Client{Timeout: time.Duration(1) * time.Minute}
Expand Down
4 changes: 1 addition & 3 deletions pkg/api/dir_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ import (
"net/http"

"github.com/fairdatasociety/fairOS-dfs/pkg/auth"

"resenje.org/jsonhttp"

"github.com/fairdatasociety/fairOS-dfs/pkg/dfs"
"github.com/fairdatasociety/fairOS-dfs/pkg/dir"
"github.com/fairdatasociety/fairOS-dfs/pkg/file"
p "github.com/fairdatasociety/fairOS-dfs/pkg/pod"
"resenje.org/jsonhttp"
)

// ListFileResponse is used to list directories and files
Expand Down
7 changes: 7 additions & 0 deletions pkg/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import (
"github.com/fairdatasociety/fairOS-dfs/pkg/logging"
)

const (
feedCacheSize = 100
feedCacheTTL = 0
)

// Handler is the api handler
type Handler struct {
ctx context.Context
Expand Down Expand Up @@ -54,6 +59,8 @@ func New(ctx context.Context, opts *Options) (*Handler, error) {
SubscriptionConfig: opts.SubscriptionConfig,
Logger: opts.Logger,
FeedTracker: opts.FeedTracker,
FeedCacheSize: feedCacheSize,
FeedCacheTTL: feedCacheTTL,
}
api, err := dfs.NewDfsAPI(ctx, dfsOpts)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collection/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestBatchIndex(t *testing.T) {
if err != nil {
t.Fatal(err)
}
fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger)
fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger)
user := acc.GetAddress(account.UserAccountIndex)
podPassword, _ := utils.GetRandString(pod.PasswordLength)
t.Run("batch-add-docs", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/collection/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestDocumentStore(t *testing.T) {
if err != nil {
t.Fatal(err)
}
fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger)
fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger)
user := acc.GetAddress(account.UserAccountIndex)
tm := taskmanager.New(1, 10, time.Second*15, logger)
defer func() {
Expand All @@ -79,7 +79,7 @@ func TestDocumentStore(t *testing.T) {
docStore := collection.NewDocumentStore("pod1", fd, ai, user, file, tm, mockClient, logger)
podPassword, _ := utils.GetRandString(pod.PasswordLength)
t.Run("create_document_db_errors", func(t *testing.T) {
nilFd := feed.New(&account.Info{}, mockClient, logger)
nilFd := feed.New(&account.Info{}, mockClient, 500, 0, logger)
nilDocStore := collection.NewDocumentStore("pod1", nilFd, ai, user, file, tm, mockClient, logger)
err := nilDocStore.CreateDocumentDB("docdb_err", podPassword, nil, true)
if !errors.Is(err, collection.ErrReadOnlyIndex) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collection/index_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestIndexAPI(t *testing.T) {
if err != nil {
t.Fatal(err)
}
fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger)
fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger)
user := acc.GetAddress(account.UserAccountIndex)
podPassword, _ := utils.GetRandString(pod.PasswordLength)
t.Run("get-doc", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collection/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestIndex(t *testing.T) {
if err != nil {
t.Fatal(err)
}
fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger)
fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger)
user := acc.GetAddress(account.UserAccountIndex)
podPassword, _ := utils.GetRandString(pod.PasswordLength)
t.Run("create_index", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collection/iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestIndexIterator(t *testing.T) {
if err != nil {
t.Fatal(err)
}
fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger)
fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger)
user := acc.GetAddress(account.UserAccountIndex)
podPassword, _ := utils.GetRandString(pod.PasswordLength)
t.Run("iterate_all_string_keys", func(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/collection/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ func (kv *KeyValue) DeleteKVTable(name, encryptionPassword string) error {
return kv.storeKVTables(kvtables, encryptionPassword)
}

func (kv *KeyValue) Commit() {
kv.fd.CommitFeeds()
}

// DeleteAllKVTables deletes all key value tables with all their index and data entries.
func (kv *KeyValue) DeleteAllKVTables(encryptionPassword string) error {
if kv.fd.IsReadOnlyFeed() { // skipcq: TCV-001
Expand Down
Loading

0 comments on commit ff3a4ec

Please sign in to comment.