From fb198ed825b542c7f495ca9e732d4a2dff08ff9d Mon Sep 17 00:00:00 2001 From: asabya Date: Fri, 6 Oct 2023 16:33:32 +0530 Subject: [PATCH] cacheSize and cacheTTL --- cmd/dfs/cmd/server_test.go | 4 +- pkg/api/dir_ls.go | 4 +- pkg/api/handler.go | 7 +++ pkg/collection/batch_test.go | 2 +- pkg/collection/document_test.go | 4 +- pkg/collection/index_api_test.go | 2 +- pkg/collection/index_test.go | 2 +- pkg/collection/iterator_test.go | 2 +- pkg/collection/kv.go | 4 ++ pkg/collection/kv_test.go | 78 ++++++++++++++++---------------- pkg/dfs/api.go | 8 +++- pkg/dfs/pod_api.go | 8 ++-- pkg/dir/chmod_test.go | 2 +- pkg/dir/dir_present_test.go | 2 +- pkg/dir/dir_test.go | 2 +- pkg/dir/ls_test.go | 2 +- pkg/dir/mkdir_test.go | 2 +- pkg/dir/rename_test.go | 2 +- pkg/dir/rmdir_test.go | 6 +-- pkg/dir/stat_test.go | 2 +- pkg/dir/sync_test.go | 2 +- pkg/feed/api.go | 4 +- pkg/feed/feed_test.go | 36 +++++++-------- pkg/feed/handler.go | 17 +++---- pkg/feed/handler_test.go | 4 +- pkg/feed/tracker/tracker_test.go | 14 +++--- pkg/file/chmod_test.go | 2 +- pkg/file/download_test.go | 2 +- pkg/file/ls_test.go | 2 +- pkg/file/rename_test.go | 2 +- pkg/file/rm_test.go | 2 +- pkg/file/stat_test.go | 2 +- pkg/file/status_test.go | 2 +- pkg/file/upload_test.go | 2 +- pkg/file/writeAt_test.go | 2 +- pkg/pod/fork.go | 2 +- pkg/pod/new.go | 4 +- pkg/pod/open.go | 10 ++-- pkg/pod/pod.go | 39 +++++++++------- pkg/test/close_test.go | 4 +- pkg/test/del_test.go | 4 +- pkg/test/delete_test.go | 2 +- pkg/test/fork_test.go | 4 +- pkg/test/integration_test.go | 2 +- pkg/test/lite_test.go | 4 +- pkg/test/login_test.go | 6 +-- pkg/test/logout_test.go | 2 +- pkg/test/ls_test.go | 4 +- pkg/test/max_pod_test.go | 4 +- pkg/test/new_test.go | 6 +-- pkg/test/open_test.go | 4 +- pkg/test/pod_new_test.go | 4 +- pkg/test/pod_sharing_test.go | 32 ++++++------- pkg/test/pod_stat_test.go | 4 +- pkg/test/stat_test.go | 4 +- pkg/test/subscription_test.go | 8 ++-- pkg/test/sync_test.go | 4 +- pkg/test/user_sharing_test.go | 12 ++--- pkg/user/lite.go | 4 +- pkg/user/login.go | 10 ++-- pkg/user/new.go | 4 +- pkg/user/users.go | 18 +++++--- 62 files changed, 236 insertions(+), 209 deletions(-) diff --git a/cmd/dfs/cmd/server_test.go b/cmd/dfs/cmd/server_test.go index 0afe53bf..a34b3f99 100644 --- a/cmd/dfs/cmd/server_test.go +++ b/cmd/dfs/cmd/server_test.go @@ -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() @@ -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} diff --git a/pkg/api/dir_ls.go b/pkg/api/dir_ls.go index 48ab7e79..5d32d73a 100644 --- a/pkg/api/dir_ls.go +++ b/pkg/api/dir_ls.go @@ -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 diff --git a/pkg/api/handler.go b/pkg/api/handler.go index 765971de..736c5bdd 100644 --- a/pkg/api/handler.go +++ b/pkg/api/handler.go @@ -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 @@ -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 { diff --git a/pkg/collection/batch_test.go b/pkg/collection/batch_test.go index 1147b206..ef9ab106 100644 --- a/pkg/collection/batch_test.go +++ b/pkg/collection/batch_test.go @@ -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) { diff --git a/pkg/collection/document_test.go b/pkg/collection/document_test.go index f15e7b5f..90016d4b 100644 --- a/pkg/collection/document_test.go +++ b/pkg/collection/document_test.go @@ -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() { @@ -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) { diff --git a/pkg/collection/index_api_test.go b/pkg/collection/index_api_test.go index d0bea459..0a7b7923 100644 --- a/pkg/collection/index_api_test.go +++ b/pkg/collection/index_api_test.go @@ -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) { diff --git a/pkg/collection/index_test.go b/pkg/collection/index_test.go index 4140a689..68337584 100644 --- a/pkg/collection/index_test.go +++ b/pkg/collection/index_test.go @@ -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) { diff --git a/pkg/collection/iterator_test.go b/pkg/collection/iterator_test.go index 78c19bff..7602810d 100644 --- a/pkg/collection/iterator_test.go +++ b/pkg/collection/iterator_test.go @@ -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) { diff --git a/pkg/collection/kv.go b/pkg/collection/kv.go index ccea30cf..5fc92ea1 100644 --- a/pkg/collection/kv.go +++ b/pkg/collection/kv.go @@ -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 diff --git a/pkg/collection/kv_test.go b/pkg/collection/kv_test.go index a50535c5..b813d4d9 100644 --- a/pkg/collection/kv_test.go +++ b/pkg/collection/kv_test.go @@ -66,7 +66,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -104,7 +104,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -138,7 +138,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -177,7 +177,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -216,7 +216,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -250,7 +250,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -342,7 +342,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -374,7 +374,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -394,7 +394,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -423,7 +423,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -442,7 +442,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -489,7 +489,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -540,7 +540,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -579,7 +579,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -606,7 +606,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -671,7 +671,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -694,7 +694,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -727,7 +727,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -751,7 +751,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -817,7 +817,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) defer fd.CommitFeeds() user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) @@ -879,7 +879,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) podPassword, _ := utils.GetRandString(pod.PasswordLength) @@ -888,7 +888,7 @@ func TestKeyValueStore(t *testing.T) { t.Fatal(err) } _, err = kvStore.KVCount("kv_table_batch_count") - if err != collection.ErrKVTableNotOpened { + if !errors.Is(err, collection.ErrKVTableNotOpened) { t.Fatal("should have returned error ", collection.ErrKVTableNotOpened) } err = kvStore.OpenKVTable("kv_table_batch_count", podPassword) @@ -912,7 +912,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) podPassword, _ := utils.GetRandString(pod.PasswordLength) @@ -965,7 +965,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) podPassword, _ := utils.GetRandString(pod.PasswordLength) @@ -1029,7 +1029,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) podPassword, _ := utils.GetRandString(pod.PasswordLength) @@ -1110,7 +1110,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) podPassword, _ := utils.GetRandString(pod.PasswordLength) @@ -1207,7 +1207,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) podPassword, _ := utils.GetRandString(pod.PasswordLength) @@ -1251,7 +1251,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) podPassword, _ := utils.GetRandString(pod.PasswordLength) @@ -1296,7 +1296,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) podPassword, _ := utils.GetRandString(pod.PasswordLength) @@ -1360,7 +1360,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) podPassword, _ := utils.GetRandString(pod.PasswordLength) @@ -1418,7 +1418,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) podPassword, _ := utils.GetRandString(pod.PasswordLength) @@ -1459,7 +1459,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) podPassword, _ := utils.GetRandString(pod.PasswordLength) @@ -1490,7 +1490,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) podPassword, _ := utils.GetRandString(pod.PasswordLength) @@ -1517,7 +1517,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) podPassword, _ := utils.GetRandString(pod.PasswordLength) @@ -1544,7 +1544,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) podPassword, _ := utils.GetRandString(pod.PasswordLength) @@ -1571,7 +1571,7 @@ func TestKeyValueStore(t *testing.T) { Post: mockpost.New(mockpost.WithAcceptAll()), }) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) user := acc.GetAddress(account.UserAccountIndex) kvStore := collection.NewKeyValueStore("pod1", fd, ai, user, mockClient, logger) podPassword, _ := utils.GetRandString(pod.PasswordLength) @@ -1587,7 +1587,7 @@ func TestKeyValueStore(t *testing.T) { }) } -func addRandomStrings(t *testing.T, kvStore *collection.KeyValue, count int, tableName string) ([]string, []string, error) { +func addRandomStrings(_ *testing.T, kvStore *collection.KeyValue, count int, tableName string) ([]string, []string, error) { var keys []string var values []string for i := 0; i < count; i++ { @@ -1618,7 +1618,7 @@ func addRandomStrings(t *testing.T, kvStore *collection.KeyValue, count int, tab return keys, values, nil } -func addRandomNumbersAsString(t *testing.T, kvStore *collection.KeyValue, count int, tableName string) ([]string, []string, error) { +func addRandomNumbersAsString(_ *testing.T, kvStore *collection.KeyValue, count int, tableName string) ([]string, []string, error) { var keys []string var values []string for i := 0; i < count; i++ { @@ -1645,7 +1645,7 @@ func addRandomNumbersAsString(t *testing.T, kvStore *collection.KeyValue, count return keys, values, nil } -func addRandomNumbers(t *testing.T, kvStore *collection.KeyValue, count int, tableName string) ([]int, []int, error) { +func addRandomNumbers(_ *testing.T, kvStore *collection.KeyValue, count int, tableName string) ([]int, []int, error) { var keys []int var values []int for i := 0; i < count; i++ { diff --git a/pkg/dfs/api.go b/pkg/dfs/api.go index d37e3595..b6c6ebcd 100644 --- a/pkg/dfs/api.go +++ b/pkg/dfs/api.go @@ -47,6 +47,8 @@ type API struct { tm *taskmanager.TaskManager sm subscriptionManager.SubscriptionManager shouldInitFeedTracker bool + feedCacheSize int + feedCacheTTL time.Duration io.Closer } @@ -57,6 +59,8 @@ type Options struct { SubscriptionConfig *contracts.SubscriptionConfig Logger logging.Logger FeedTracker bool + FeedCacheSize int + FeedCacheTTL time.Duration } // NewDfsAPI is the main entry point for the df controller. @@ -75,7 +79,7 @@ func NewDfsAPI(ctx context.Context, opts *Options) (*API, error) { logger.Errorf("dfs: bee client initialisation failed") return nil, errBeeClient } - users := user.NewUsers(c, ens, logger) + users := user.NewUsers(c, ens, opts.FeedCacheSize, opts.FeedCacheTTL, logger) var sm subscriptionManager.SubscriptionManager if opts.SubscriptionConfig != nil { @@ -99,6 +103,8 @@ func NewDfsAPI(ctx context.Context, opts *Options) (*API, error) { logger: logger, tm: taskmanager.New(10, defaultMaxWorkers, time.Second*15, tmLogger), sm: sm, + feedCacheSize: opts.FeedCacheSize, + feedCacheTTL: opts.FeedCacheTTL, }, nil } diff --git a/pkg/dfs/pod_api.go b/pkg/dfs/pod_api.go index d2468089..02fd94c1 100644 --- a/pkg/dfs/pod_api.go +++ b/pkg/dfs/pod_api.go @@ -267,7 +267,7 @@ func (a *API) PublicPodFileDownload(pod *pod.ShareInfo, filePath string) (io.Rea address := utils.HexToAddress(pod.Address) accountInfo.SetAddress(address) - fd := feed.New(accountInfo, a.client, a.logger) + fd := feed.New(accountInfo, a.client, a.feedCacheSize, a.feedCacheTTL, a.logger) topic := utils.HashString(filePath) _, metaBytes, err := fd.GetFeedData(topic, accountInfo.GetAddress(), []byte(pod.Password), false) if err != nil { @@ -307,7 +307,7 @@ func (a *API) PublicPodKVEntryGet(pod *pod.ShareInfo, name, key string) ([]strin address := utils.HexToAddress(pod.Address) accountInfo.SetAddress(address) - fd := feed.New(accountInfo, a.client, a.logger) + fd := feed.New(accountInfo, a.client, a.feedCacheSize, a.feedCacheTTL, a.logger) kvStore := c.NewKeyValueStore(pod.PodName, fd, accountInfo, address, a.client, a.logger) err := kvStore.OpenKVTable(name, pod.Password) @@ -324,7 +324,7 @@ func (a *API) PublicPodKVGetter(pod *pod.ShareInfo) KVGetter { address := utils.HexToAddress(pod.Address) accountInfo.SetAddress(address) - fd := feed.New(accountInfo, a.client, a.logger) + fd := feed.New(accountInfo, a.client, a.feedCacheSize, a.feedCacheTTL, a.logger) return c.NewKeyValueStore(pod.PodName, fd, accountInfo, address, a.client, a.logger) } @@ -335,7 +335,7 @@ func (a *API) PublicPodDisLs(pod *pod.ShareInfo, dirPathToLs string) ([]dir.Entr address := utils.HexToAddress(pod.Address) accountInfo.SetAddress(address) - fd := feed.New(accountInfo, a.client, a.logger) + fd := feed.New(accountInfo, a.client, a.feedCacheSize, a.feedCacheTTL, a.logger) dirNameWithPath := filepath.ToSlash(dirPathToLs) topic := utils.HashString(dirNameWithPath) diff --git a/pkg/dir/chmod_test.go b/pkg/dir/chmod_test.go index 7e5c2dc4..62c134da 100644 --- a/pkg/dir/chmod_test.go +++ b/pkg/dir/chmod_test.go @@ -42,7 +42,7 @@ func TestChmod(t *testing.T) { if err != nil { t.Fatal(err) } - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) mockFile := fm.NewMockFile() tm := taskmanager.New(1, 10, time.Second*15, logger) diff --git a/pkg/dir/dir_present_test.go b/pkg/dir/dir_present_test.go index 80237313..d3d3a08c 100644 --- a/pkg/dir/dir_present_test.go +++ b/pkg/dir/dir_present_test.go @@ -57,7 +57,7 @@ func TestDirPresent(t *testing.T) { if err != nil { t.Fatal(err) } - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) mockFile := fm.NewMockFile() tm := taskmanager.New(1, 10, time.Second*15, logger) diff --git a/pkg/dir/dir_test.go b/pkg/dir/dir_test.go index 6fa65e42..86e697ce 100644 --- a/pkg/dir/dir_test.go +++ b/pkg/dir/dir_test.go @@ -40,7 +40,7 @@ func TestDirRmAllFromMap(t *testing.T) { if err != nil { t.Fatal(err) } - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) mockFile := fm.NewMockFile() tm := taskmanager.New(1, 10, time.Second*15, logger) diff --git a/pkg/dir/ls_test.go b/pkg/dir/ls_test.go index 12a26a96..5a34cc8a 100644 --- a/pkg/dir/ls_test.go +++ b/pkg/dir/ls_test.go @@ -61,7 +61,7 @@ func TestListDirectory(t *testing.T) { if err != nil { t.Fatal(err) } - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) mockFile := fm.NewMockFile() tm := taskmanager.New(1, 10, time.Second*15, logger) diff --git a/pkg/dir/mkdir_test.go b/pkg/dir/mkdir_test.go index 66e8d81a..820ab6d6 100644 --- a/pkg/dir/mkdir_test.go +++ b/pkg/dir/mkdir_test.go @@ -63,7 +63,7 @@ func TestMkdir(t *testing.T) { _ = tm.Stop(context.Background()) }() - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) mockFile := fm.NewMockFile() diff --git a/pkg/dir/rename_test.go b/pkg/dir/rename_test.go index f11141e6..71b1486f 100644 --- a/pkg/dir/rename_test.go +++ b/pkg/dir/rename_test.go @@ -43,7 +43,7 @@ func TestRenameDirectory(t *testing.T) { if err != nil { t.Fatal(err) } - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) tm := taskmanager.New(1, 10, time.Second*15, logger) defer func() { diff --git a/pkg/dir/rmdir_test.go b/pkg/dir/rmdir_test.go index 3ce0400c..63a53524 100644 --- a/pkg/dir/rmdir_test.go +++ b/pkg/dir/rmdir_test.go @@ -65,7 +65,7 @@ func TestRmdir(t *testing.T) { _ = tm.Stop(context.Background()) }() - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) mockFile := fm.NewMockFile() @@ -197,7 +197,7 @@ func TestRmRootDirByPath(t *testing.T) { if err != nil { t.Fatal(err) } - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) mockFile := fm.NewMockFile() tm := taskmanager.New(1, 10, time.Second*15, logger) @@ -300,7 +300,7 @@ func TestRmRootDir(t *testing.T) { _ = tm.Stop(context.Background()) }() - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) mockFile := fm.NewMockFile() diff --git a/pkg/dir/stat_test.go b/pkg/dir/stat_test.go index 762badcd..1bd84396 100644 --- a/pkg/dir/stat_test.go +++ b/pkg/dir/stat_test.go @@ -60,7 +60,7 @@ func TestStat(t *testing.T) { if err != nil { t.Fatal(err) } - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) mockFile := fm.NewMockFile() tm := taskmanager.New(1, 10, time.Second*15, logger) diff --git a/pkg/dir/sync_test.go b/pkg/dir/sync_test.go index 0df6f9aa..4b03509c 100644 --- a/pkg/dir/sync_test.go +++ b/pkg/dir/sync_test.go @@ -62,7 +62,7 @@ func TestSync(t *testing.T) { if err != nil { t.Fatal(err) } - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) mockFile := fm.NewMockFile() tm := taskmanager.New(1, 10, time.Second*15, logger) diff --git a/pkg/feed/api.go b/pkg/feed/api.go index 842d2ded..f818d1bd 100644 --- a/pkg/feed/api.go +++ b/pkg/feed/api.go @@ -71,10 +71,10 @@ type request struct { } // New create the main feed object which is used to create/update/delete feeds. -func New(accountInfo *account.Info, client blockstore.Client, logger logging.Logger) *API { +func New(accountInfo *account.Info, client blockstore.Client, feedCacheSize int, feedCacheTTL time.Duration, logger logging.Logger) *API { bmtPool := bmtlegacy.NewTreePool(hashFunc, swarm.Branches, bmtlegacy.PoolSize) return &API{ - handler: NewHandler(accountInfo, client, bmtPool), + handler: NewHandler(accountInfo, client, bmtPool, feedCacheSize, feedCacheTTL, logger), accountInfo: accountInfo, logger: logger, } diff --git a/pkg/feed/feed_test.go b/pkg/feed/feed_test.go index c0e8baff..8026d4ba 100644 --- a/pkg/feed/feed_test.go +++ b/pkg/feed/feed_test.go @@ -60,7 +60,7 @@ func TestFeed(t *testing.T) { } user := acc.GetAddress(account.UserAccountIndex) accountInfo := acc.GetUserAccountInfo() - fd := feed.New(accountInfo, client, logger) + fd := feed.New(accountInfo, client, 500, 0, logger) topic := utils.HashString("topic1") data := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} err = fd.CreateFeed(user, topic, data, nil) @@ -94,7 +94,7 @@ func TestFeed(t *testing.T) { accountInfo := acc.GetUserAccountInfo() // create feed from user - fd1 := feed.New(accountInfo, client, logger) + fd1 := feed.New(accountInfo, client, 500, 0, logger) topic := utils.HashString("topic1") data := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} err = fd1.CreateFeed(user, topic, data, nil) @@ -103,7 +103,7 @@ func TestFeed(t *testing.T) { } fd1.CommitFeeds() // check if you can read the data from user2 - fd2 := feed.New(accountInfo, client, logger) + fd2 := feed.New(accountInfo, client, 500, 0, logger) _, rcvdData, err := fd2.GetFeedData(topic, user, nil, false) if err != nil { t.Fatal(err) @@ -123,7 +123,7 @@ func TestFeed(t *testing.T) { user := acc.GetAddress(account.UserAccountIndex) accountInfo := acc.GetUserAccountInfo() - fd := feed.New(accountInfo, client, logger) + fd := feed.New(accountInfo, client, 500, 0, logger) topic := utils.HashString("topic2") // check if the data and address is present and is same as stored @@ -143,7 +143,7 @@ func TestFeed(t *testing.T) { user := acc.GetAddress(account.UserAccountIndex) // create feed from user - fd1 := feed.New(accountInfo, client, logger) + fd1 := feed.New(accountInfo, client, 500, 0, logger) topic := utils.HashString("topic1") data := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} err = fd1.CreateFeed(user, topic, data, nil) @@ -160,7 +160,7 @@ func TestFeed(t *testing.T) { user2 := acc2.GetAddress(account.UserAccountIndex) // check if you can read the data from user2 - fd2 := feed.New(accountInfo2, client, logger) + fd2 := feed.New(accountInfo2, client, 500, 0, logger) rcvdAddr, rcvdData, err := fd2.GetFeedData(topic, user2, nil, false) if err != nil && err.Error() != "feed does not exist or was not updated yet" { t.Fatal(err) @@ -179,7 +179,7 @@ func TestFeed(t *testing.T) { } user := acc.GetAddress(account.UserAccountIndex) accountInfo := acc.GetUserAccountInfo() - fd := feed.New(accountInfo, client, logger) + fd := feed.New(accountInfo, client, 500, 0, logger) topic := utils.HashString("topic3") data := []byte{0} err = fd.CreateFeed(user, topic, data, nil) @@ -224,7 +224,7 @@ func TestFeed(t *testing.T) { } user := acc.GetAddress(account.UserAccountIndex) accountInfo := acc.GetUserAccountInfo() - fd := feed.New(accountInfo, client, logger) + fd := feed.New(accountInfo, client, 500, 0, logger) topic := utils.HashString("feed-topic1") data := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} addr, err := fd.CreateFeedFromTopic(topic, user, data) @@ -258,7 +258,7 @@ func TestFeed(t *testing.T) { } user := acc.GetAddress(account.UserAccountIndex) accountInfo := acc.GetUserAccountInfo() - fd := feed.New(accountInfo, client, logger) + fd := feed.New(accountInfo, client, 500, 0, logger) topic := utils.HashString("feed-topic1") data := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} _, err = fd.CreateFeedFromTopic(topic, user, data) @@ -284,9 +284,9 @@ func TestFeed(t *testing.T) { } user := acc.GetAddress(account.UserAccountIndex) accountInfo := acc.GetUserAccountInfo() - nilFd := feed.New(&account.Info{}, client, logger) + nilFd := feed.New(&account.Info{}, client, 500, 0, logger) - fd := feed.New(accountInfo, client, logger) + fd := feed.New(accountInfo, client, 500, 0, logger) topic := utils.HashString("feed-topic1") data := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} @@ -312,7 +312,7 @@ func TestFeed(t *testing.T) { }) t.Run("create-feed-from-topic-errors", func(t *testing.T) { - nilFd := feed.New(&account.Info{}, client, logger) + nilFd := feed.New(&account.Info{}, client, 500, 0, logger) acc := account.New(logger) _, _, err := acc.CreateUserAccount("") if err != nil { @@ -320,7 +320,7 @@ func TestFeed(t *testing.T) { } user := acc.GetAddress(account.UserAccountIndex) accountInfo := acc.GetUserAccountInfo() - fd := feed.New(accountInfo, client, logger) + fd := feed.New(accountInfo, client, 500, 0, logger) topic := utils.HashString("feed-topic1") data := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} @@ -346,7 +346,7 @@ func TestFeed(t *testing.T) { }) t.Run("feed-update-errors", func(t *testing.T) { - nilFd := feed.New(&account.Info{}, client, logger) + nilFd := feed.New(&account.Info{}, client, 500, 0, logger) acc := account.New(logger) _, _, err := acc.CreateUserAccount("") if err != nil { @@ -354,7 +354,7 @@ func TestFeed(t *testing.T) { } user := acc.GetAddress(account.UserAccountIndex) accountInfo := acc.GetUserAccountInfo() - fd := feed.New(accountInfo, client, logger) + fd := feed.New(accountInfo, client, 500, 0, logger) topic := utils.HashString("feed-topic1") data := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} @@ -380,7 +380,7 @@ func TestFeed(t *testing.T) { }) t.Run("feed-delete-errors", func(t *testing.T) { - nilFd := feed.New(&account.Info{}, client, logger) + nilFd := feed.New(&account.Info{}, client, 500, 0, logger) acc := account.New(logger) _, _, err := acc.CreateUserAccount("") if err != nil { @@ -388,7 +388,7 @@ func TestFeed(t *testing.T) { } user := acc.GetAddress(account.UserAccountIndex) accountInfo := acc.GetUserAccountInfo() - fd := feed.New(accountInfo, client, logger) + fd := feed.New(accountInfo, client, 500, 0, logger) topic := utils.HashString("feed-topic1") data := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} @@ -409,7 +409,7 @@ func TestFeed(t *testing.T) { }) t.Run("feed-from-topic-delete-errors", func(t *testing.T) { - nilFd := feed.New(&account.Info{}, client, logger) + nilFd := feed.New(&account.Info{}, client, 500, 0, logger) acc := account.New(logger) _, _, err := acc.CreateUserAccount("") if err != nil { diff --git a/pkg/feed/handler.go b/pkg/feed/handler.go index 086f8c93..c801cfa1 100644 --- a/pkg/feed/handler.go +++ b/pkg/feed/handler.go @@ -24,6 +24,7 @@ import ( "encoding/hex" "errors" "fmt" + "github.com/fairdatasociety/fairOS-dfs/pkg/logging" "hash" "strings" "sync" @@ -59,8 +60,8 @@ type Handler struct { HashSize int cache map[uint64]*CacheEntry cacheLock sync.RWMutex - - pool *expirable.LRU[string, *feedItem] + logger logging.Logger + pool *expirable.LRU[string, *feedItem] } // hashPool contains a pool of ready hashers @@ -76,12 +77,13 @@ func init() { } // NewHandler the main handler object that handles all the feed related functions. -func NewHandler(accountInfo *account.Info, client blockstore.Client, hasherPool *bmtlegacy.TreePool) *Handler { +func NewHandler(accountInfo *account.Info, client blockstore.Client, hasherPool *bmtlegacy.TreePool, feedCacheSize int, feedCacheTTL time.Duration, logger logging.Logger) *Handler { fh := &Handler{ accountInfo: accountInfo, client: client, hasherPool: hasherPool, cache: make(map[uint64]*CacheEntry), + logger: logger, } for i := 0; i < hasherCount; i++ { hashfunc := crypto.SHA256.New() @@ -90,22 +92,21 @@ func NewHandler(accountInfo *account.Info, client blockstore.Client, hasherPool } hashPool.Put(hashfunc) } - fh.pool = expirable.NewLRU(100, func(key string, value *feedItem) { + fh.pool = expirable.NewLRU(feedCacheSize, func(key string, value *feedItem) { if value.ShouldCreate { _, _, err := fh.createSoc(value.User, value.AccountInfo, value.Topic, value.Data) if err != nil { - // TODO log error - fmt.Println("failed to createSoc onEvict", err) + logger.Errorf("failed to createSoc onEvict from : %v\n", err) return } } _, _, err := fh.updateSoc(value.User, value.AccountInfo, value.Topic, value.Data) if err != nil { - // TODO log error + logger.Errorf("failed to updateSoc onEvict: %v\n", err) fmt.Println("failed to updateSoc onEvict", err) return } - }, 0) + }, feedCacheTTL) return fh } diff --git a/pkg/feed/handler_test.go b/pkg/feed/handler_test.go index 29d3b9f0..bbb31a6a 100644 --- a/pkg/feed/handler_test.go +++ b/pkg/feed/handler_test.go @@ -33,7 +33,7 @@ func TestHandler(t *testing.T) { accountInfo := acc.GetUserAccountInfo() bmtPool := bmtlegacy.NewTreePool(hashFunc, swarm.Branches, bmtlegacy.PoolSize) - handler := NewHandler(accountInfo, client, bmtPool) + handler := NewHandler(accountInfo, client, bmtPool, 500, 0, logger) //defer handler.Close() if handler == nil { @@ -50,7 +50,7 @@ func TestHandler(t *testing.T) { accountInfo := acc.GetUserAccountInfo() bmtPool := bmtlegacy.NewTreePool(hashFunc, swarm.Branches, bmtlegacy.PoolSize) - handler := NewHandler(accountInfo, client, bmtPool) + handler := NewHandler(accountInfo, client, bmtPool, 500, 0, logger) //defer handler.Close() if handler == nil { diff --git a/pkg/feed/tracker/tracker_test.go b/pkg/feed/tracker/tracker_test.go index ff2c7d89..79472e14 100644 --- a/pkg/feed/tracker/tracker_test.go +++ b/pkg/feed/tracker/tracker_test.go @@ -42,7 +42,7 @@ func TestTimeKeeper(t *testing.T) { client := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) t.Run("level-get-from-same-feed-pointer", func(t *testing.T) { - fd1 := feed.New(accountInfo1, client, logger) + fd1 := feed.New(accountInfo1, client, 500, 0, logger) db, err := leveldb.Open(NewMemStorage(fd1, client, user1, "username", "password", logger), nil) if err != nil { t.Fatal(err) @@ -78,7 +78,7 @@ func TestTimeKeeper(t *testing.T) { }) t.Run("level-get-from-different-feed-pointer", func(t *testing.T) { - fd1 := feed.New(accountInfo1, client, logger) + fd1 := feed.New(accountInfo1, client, 500, 0, logger) db, err := leveldb.Open(NewMemStorage(fd1, client, user1, "username", "password", logger), nil) if err != nil { t.Fatal(err) @@ -104,7 +104,7 @@ func TestTimeKeeper(t *testing.T) { t.Fatal(err) } - fd2 := feed.New(accountInfo1, client, logger) + fd2 := feed.New(accountInfo1, client, 500, 0, logger) db2, err := leveldb.Open(NewMemStorage(fd2, client, user1, "username", "password", logger), nil) if err != nil { t.Fatal(err) @@ -124,7 +124,7 @@ func TestTimeKeeper(t *testing.T) { }) t.Run("level-get-from-multiple-different-feed-pointer", func(t *testing.T) { - fd1 := feed.New(accountInfo1, client, logger) + fd1 := feed.New(accountInfo1, client, 500, 0, logger) db, err := leveldb.Open(NewMemStorage(fd1, client, user1, "username", "password", logger), nil) if err != nil { t.Fatal(err) @@ -148,7 +148,7 @@ func TestTimeKeeper(t *testing.T) { t.Fatal(err) } - fd2 := feed.New(accountInfo1, client, logger) + fd2 := feed.New(accountInfo1, client, 500, 0, logger) db2, err := leveldb.Open(NewMemStorage(fd2, client, user1, "username", "password", logger), nil) if err != nil { t.Fatal(err) @@ -167,7 +167,7 @@ func TestTimeKeeper(t *testing.T) { if err != nil { t.Fatal(err) } - fd3 := feed.New(accountInfo1, client, logger) + fd3 := feed.New(accountInfo1, client, 500, 0, logger) db3, err := leveldb.Open(NewMemStorage(fd3, client, user1, "username", "password", logger), nil) if err != nil { t.Fatal(err) @@ -186,7 +186,7 @@ func TestTimeKeeper(t *testing.T) { if err != nil { t.Fatal(err) } - fd4 := feed.New(accountInfo1, client, logger) + fd4 := feed.New(accountInfo1, client, 500, 0, logger) db4, err := leveldb.Open(NewMemStorage(fd4, client, user1, "username", "password", logger), nil) if err != nil { t.Fatal(err) diff --git a/pkg/file/chmod_test.go b/pkg/file/chmod_test.go index 5cb69f4d..b8888a0e 100644 --- a/pkg/file/chmod_test.go +++ b/pkg/file/chmod_test.go @@ -42,7 +42,7 @@ func TestChmod(t *testing.T) { if err != nil { t.Fatal(err) } - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) tm := taskmanager.New(1, 10, time.Second*15, logger) defer func() { diff --git a/pkg/file/download_test.go b/pkg/file/download_test.go index d8faebfe..577418d3 100644 --- a/pkg/file/download_test.go +++ b/pkg/file/download_test.go @@ -57,7 +57,7 @@ func TestDownload(t *testing.T) { pod1AccountInfo, err := acc.CreatePodAccount(1, false) require.NoError(t, err) - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) tm := taskmanager.New(1, 10, time.Second*15, logger) defer func() { diff --git a/pkg/file/ls_test.go b/pkg/file/ls_test.go index 8465168a..9bfab141 100644 --- a/pkg/file/ls_test.go +++ b/pkg/file/ls_test.go @@ -57,7 +57,7 @@ func TestListFiles(t *testing.T) { if err != nil { t.Fatal(err) } - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) tm := taskmanager.New(1, 10, time.Second*15, logger) defer func() { diff --git a/pkg/file/rename_test.go b/pkg/file/rename_test.go index a9467ddf..9eb5a129 100644 --- a/pkg/file/rename_test.go +++ b/pkg/file/rename_test.go @@ -41,7 +41,7 @@ func TestRename(t *testing.T) { if err != nil { t.Fatal(err) } - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) tm := taskmanager.New(1, 10, time.Second*15, logger) defer func() { diff --git a/pkg/file/rm_test.go b/pkg/file/rm_test.go index 5d26e422..6a739dae 100644 --- a/pkg/file/rm_test.go +++ b/pkg/file/rm_test.go @@ -54,7 +54,7 @@ func TestRemoveFile(t *testing.T) { pod1AccountInfo, err := acc.CreatePodAccount(1, false) require.NoError(t, err) - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) tm := taskmanager.New(1, 10, time.Second*15, logger) defer func() { diff --git a/pkg/file/stat_test.go b/pkg/file/stat_test.go index e5eb44b2..a81bbb87 100644 --- a/pkg/file/stat_test.go +++ b/pkg/file/stat_test.go @@ -57,7 +57,7 @@ func TestStat(t *testing.T) { if err != nil { t.Fatal(err) } - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) tm := taskmanager.New(1, 10, time.Second*15, logger) defer func() { diff --git a/pkg/file/status_test.go b/pkg/file/status_test.go index ded1c1be..bcf7bcb2 100644 --- a/pkg/file/status_test.go +++ b/pkg/file/status_test.go @@ -41,7 +41,7 @@ func TestStatus(t *testing.T) { if err != nil { t.Fatal(err) } - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) tm := taskmanager.New(1, 10, time.Second*15, logger) defer func() { diff --git a/pkg/file/upload_test.go b/pkg/file/upload_test.go index ef30854b..3c9a7bc2 100644 --- a/pkg/file/upload_test.go +++ b/pkg/file/upload_test.go @@ -60,7 +60,7 @@ func TestUpload(t *testing.T) { if err != nil { t.Fatal(err) } - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) tm := taskmanager.New(1, 10, time.Second*15, logger) defer func() { diff --git a/pkg/file/writeAt_test.go b/pkg/file/writeAt_test.go index 2e25512e..a307d216 100644 --- a/pkg/file/writeAt_test.go +++ b/pkg/file/writeAt_test.go @@ -50,7 +50,7 @@ func TestWriteAt(t *testing.T) { if err != nil { t.Fatal(err) } - fd := feed.New(pod1AccountInfo, mockClient, logger) + fd := feed.New(pod1AccountInfo, mockClient, 500, 0, logger) user := acc.GetAddress(1) tm := taskmanager.New(1, 10, time.Second*15, logger) defer func() { diff --git a/pkg/pod/fork.go b/pkg/pod/fork.go index abc51f39..d6eaa044 100644 --- a/pkg/pod/fork.go +++ b/pkg/pod/fork.go @@ -64,7 +64,7 @@ func (p *Pod) PodForkFromRef(forkName, refString string) error { address := utils.HexToAddress(shareInfo.Address) accountInfo.SetAddress(address) - fd := feed.New(accountInfo, p.client, p.logger) + fd := feed.New(accountInfo, p.client, p.feedCacheSize, p.feedCacheTTL, p.logger) file := f.NewFile(shareInfo.PodName, p.client, fd, accountInfo.GetAddress(), p.tm, p.logger) dir := d.NewDirectory(shareInfo.PodName, p.client, fd, accountInfo.GetAddress(), file, p.tm, p.logger) podInfo := &Info{ diff --git a/pkg/pod/new.go b/pkg/pod/new.go index 38dd2cb8..8241d635 100644 --- a/pkg/pod/new.go +++ b/pkg/pod/new.go @@ -71,7 +71,7 @@ func (p *Pod) CreatePod(podName, addressString, podPassword string) (*Info, erro address := utils.HexToAddress(addressString) accountInfo.SetAddress(address) - fd = feed.New(accountInfo, p.client, p.logger) + fd = feed.New(accountInfo, p.client, p.feedCacheSize, p.feedCacheTTL, p.logger) file = f.NewFile(podName, p.client, fd, accountInfo.GetAddress(), p.tm, p.logger) dir = d.NewDirectory(podName, p.client, fd, accountInfo.GetAddress(), file, p.tm, p.logger) @@ -107,7 +107,7 @@ func (p *Pod) CreatePod(podName, addressString, podPassword string) (*Info, erro if err != nil { // skipcq: TCV-001 return nil, err } - fd = feed.New(accountInfo, p.client, p.logger) + fd = feed.New(accountInfo, p.client, p.feedCacheSize, p.feedCacheTTL, p.logger) //fd.SetUpdateTracker(p.fd.GetUpdateTracker()) file = f.NewFile(podName, p.client, fd, accountInfo.GetAddress(), p.tm, p.logger) dir = d.NewDirectory(podName, p.client, fd, accountInfo.GetAddress(), file, p.tm, p.logger) diff --git a/pkg/pod/open.go b/pkg/pod/open.go index a1febdd2..4fad1d0b 100644 --- a/pkg/pod/open.go +++ b/pkg/pod/open.go @@ -69,7 +69,7 @@ func (p *Pod) OpenPod(podName string) (*Info, error) { address := utils.HexToAddress(addressString) accountInfo.SetAddress(address) - fd = feed.New(accountInfo, p.client, p.logger) + fd = feed.New(accountInfo, p.client, p.feedCacheSize, p.feedCacheTTL, p.logger) file = f.NewFile(podName, p.client, fd, accountInfo.GetAddress(), p.tm, p.logger) dir = d.NewDirectory(podName, p.client, fd, accountInfo.GetAddress(), file, p.tm, p.logger) @@ -87,7 +87,7 @@ func (p *Pod) OpenPod(podName string) (*Info, error) { if err != nil { // skipcq: TCV-001 return nil, err } - fd = feed.New(accountInfo, p.client, p.logger) + fd = feed.New(accountInfo, p.client, p.feedCacheSize, p.feedCacheTTL, p.logger) //_, err = tracker.InitFeedsTracker(accountInfo.GetAddress(), podName, podPassword, fd, p.client, p.logger) //if err != nil { // p.logger.Errorf("error initializing feeds tracker: %v", err) @@ -128,7 +128,7 @@ func (p *Pod) OpenFromShareInfo(si *ShareInfo) (*Info, error) { address := utils.HexToAddress(si.Address) accountInfo.SetAddress(address) - fd := feed.New(accountInfo, p.client, p.logger) + fd := feed.New(accountInfo, p.client, p.feedCacheSize, p.feedCacheTTL, p.logger) file := f.NewFile(si.PodName, p.client, fd, accountInfo.GetAddress(), p.tm, p.logger) dir := d.NewDirectory(si.PodName, p.client, fd, accountInfo.GetAddress(), file, p.tm, p.logger) @@ -195,7 +195,7 @@ func (p *Pod) OpenPodAsync(ctx context.Context, podName string) (*Info, error) { address := utils.HexToAddress(addressString) accountInfo.SetAddress(address) - fd = feed.New(accountInfo, p.client, p.logger) + fd = feed.New(accountInfo, p.client, p.feedCacheSize, p.feedCacheTTL, p.logger) file = f.NewFile(podName, p.client, fd, accountInfo.GetAddress(), p.tm, p.logger) dir = d.NewDirectory(podName, p.client, fd, accountInfo.GetAddress(), file, p.tm, p.logger) @@ -214,7 +214,7 @@ func (p *Pod) OpenPodAsync(ctx context.Context, podName string) (*Info, error) { return nil, err } - fd = feed.New(accountInfo, p.client, p.logger) + fd = feed.New(accountInfo, p.client, p.feedCacheSize, p.feedCacheTTL, p.logger) //fd.SetUpdateTracker(p.fd.GetUpdateTracker()) file = f.NewFile(podName, p.client, fd, accountInfo.GetAddress(), p.tm, p.logger) dir = d.NewDirectory(podName, p.client, fd, accountInfo.GetAddress(), file, p.tm, p.logger) diff --git a/pkg/pod/pod.go b/pkg/pod/pod.go index e7c9015f..1eb69813 100644 --- a/pkg/pod/pod.go +++ b/pkg/pod/pod.go @@ -19,6 +19,7 @@ package pod import ( "fmt" "sync" + "time" "github.com/fairdatasociety/fairOS-dfs/pkg/subscriptionManager" @@ -38,14 +39,16 @@ const ( // Pod is the main struct which acts on pods type Pod struct { - fd *feed.API - acc *account.Account - client blockstore.Client - podMap map[string]*Info // podName -> dir - podMu *sync.RWMutex - logger logging.Logger - tm taskmanager.TaskManagerGO - sm subscriptionManager.SubscriptionManager + fd *feed.API + acc *account.Account + client blockstore.Client + podMap map[string]*Info // podName -> dir + podMu *sync.RWMutex + logger logging.Logger + tm taskmanager.TaskManagerGO + sm subscriptionManager.SubscriptionManager + feedCacheSize int + feedCacheTTL time.Duration } // ListItem defines the structure for pod item @@ -69,16 +72,18 @@ type List struct { } // NewPod creates the main pod object which has all the methods related to the pods. -func NewPod(client blockstore.Client, feed *feed.API, account *account.Account, m taskmanager.TaskManagerGO, sm subscriptionManager.SubscriptionManager, logger logging.Logger) *Pod { +func NewPod(client blockstore.Client, feed *feed.API, account *account.Account, m taskmanager.TaskManagerGO, sm subscriptionManager.SubscriptionManager, feedCacheSize int, feedCacheTTL time.Duration, logger logging.Logger) *Pod { return &Pod{ - fd: feed, - acc: account, - client: client, - podMap: make(map[string]*Info), - podMu: &sync.RWMutex{}, - logger: logger, - tm: m, - sm: sm, + fd: feed, + acc: account, + client: client, + podMap: make(map[string]*Info), + podMu: &sync.RWMutex{}, + logger: logger, + tm: m, + sm: sm, + feedCacheSize: feedCacheSize, + feedCacheTTL: feedCacheTTL, } } diff --git a/pkg/test/close_test.go b/pkg/test/close_test.go index 7b68615a..1158ac44 100644 --- a/pkg/test/close_test.go +++ b/pkg/test/close_test.go @@ -52,7 +52,7 @@ func TestClose(t *testing.T) { t.Fatal(err) } - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) tm := taskmanager.New(1, 10, time.Second*15, logger) defer func() { _ = tm.Stop(context.Background()) @@ -60,7 +60,7 @@ func TestClose(t *testing.T) { sm := mock2.NewMockSubscriptionManager() - pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, logger) + pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, 500, 0, logger) podName1 := "test1" t.Run("close-pod", func(t *testing.T) { diff --git a/pkg/test/del_test.go b/pkg/test/del_test.go index 44f3c68f..ec447a88 100644 --- a/pkg/test/del_test.go +++ b/pkg/test/del_test.go @@ -55,14 +55,14 @@ func TestPodDelete(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) tm := taskmanager.New(1, 10, time.Second*15, logger) defer func() { _ = tm.Stop(context.Background()) }() sm := mock2.NewMockSubscriptionManager() - pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, logger) + pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, 500, 0, logger) podName1 := "test1" podName2 := "test2" diff --git a/pkg/test/delete_test.go b/pkg/test/delete_test.go index 666fe21c..7c416a2c 100644 --- a/pkg/test/delete_test.go +++ b/pkg/test/delete_test.go @@ -54,7 +54,7 @@ func TestDelete(t *testing.T) { t.Run("delete-user", func(t *testing.T) { ens := mock2.NewMockNamespaceManager() // create user - userObject := user.NewUsers(mockClient, ens, logger) + userObject := user.NewUsers(mockClient, ens, 500, 0, logger) sr, err := userObject.CreateNewUserV2("user1", "password1twelve", "", "", tm, sm) if err != nil { t.Fatal(err) diff --git a/pkg/test/fork_test.go b/pkg/test/fork_test.go index ff9963c2..c63e9e6a 100644 --- a/pkg/test/fork_test.go +++ b/pkg/test/fork_test.go @@ -56,10 +56,10 @@ func TestFork(t *testing.T) { defer func() { _ = tm.Stop(context.Background()) }() - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) sm := mock2.NewMockSubscriptionManager() - pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, logger) + pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, 500, 0, logger) podName1 := "test1" t.Run("fork-pod", func(t *testing.T) { diff --git a/pkg/test/integration_test.go b/pkg/test/integration_test.go index da073909..8241b20f 100644 --- a/pkg/test/integration_test.go +++ b/pkg/test/integration_test.go @@ -49,7 +49,7 @@ func TestLiteUser(t *testing.T) { logger := logging.New(io.Discard, logrus.DebugLevel) mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) - users := user.NewUsers(mockClient, ens, logger) + users := user.NewUsers(mockClient, ens, 500, 0, logger) dfsApi := dfs.NewMockDfsAPI(mockClient, users, logger) defer dfsApi.Close() t.Run("signup-login-pod-dir-file-rename", func(t *testing.T) { diff --git a/pkg/test/lite_test.go b/pkg/test/lite_test.go index 5a56b0e3..694e4dbf 100644 --- a/pkg/test/lite_test.go +++ b/pkg/test/lite_test.go @@ -39,7 +39,7 @@ func TestLite(t *testing.T) { ens := mock2.NewMockNamespaceManager() // create user - userObject := user.NewUsers(mockClient, ens, logger) + userObject := user.NewUsers(mockClient, ens, 500, 0, logger) _, _, _, err := userObject.LoadLiteUser("", "password1", "", "", tm, sm) if !errors.Is(err, user.ErrInvalidUserName) { t.Fatal(err) @@ -50,7 +50,7 @@ func TestLite(t *testing.T) { ens := mock2.NewMockNamespaceManager() // create user - userObject := user.NewUsers(mockClient, ens, logger) + userObject := user.NewUsers(mockClient, ens, 500, 0, logger) mnemonic, _, ui, err := userObject.LoadLiteUser("user1", "password1", "", "", tm, sm) if err != nil { t.Fatal(err) diff --git a/pkg/test/login_test.go b/pkg/test/login_test.go index 3030758e..c41ca6f8 100644 --- a/pkg/test/login_test.go +++ b/pkg/test/login_test.go @@ -59,7 +59,7 @@ func TestLogin(t *testing.T) { t.Run("login-user", func(t *testing.T) { ens := mock2.NewMockNamespaceManager() // create user - userObject := user.NewUsers(mockClient, ens, logger) + userObject := user.NewUsers(mockClient, ens, 500, 0, logger) sr, err := userObject.CreateNewUserV2("7e4567e7cb003804992eef11fd5c757275a4c", "password1twelve", "", "", tm, sm) if err != nil { t.Fatal(err) @@ -114,7 +114,7 @@ func TestLogin(t *testing.T) { user1 := "multicredtester" pass := "password1password1" // create user - userObject := user.NewUsers(mockClient, ens, logger) + userObject := user.NewUsers(mockClient, ens, 500, 0, logger) sr, err := userObject.CreateNewUserV2(user1, pass, "", "", tm, sm) if err != nil { t.Fatal(err) @@ -173,7 +173,7 @@ func TestLogin(t *testing.T) { ens := mock2.NewMockNamespaceManager() user1 := "multicredtester" // create user - userObject := user.NewUsers(mockClient, ens, logger) + userObject := user.NewUsers(mockClient, ens, 500, 0, logger) pass := "password1password1" sr, err := userObject.CreateNewUserV2(user1, pass, "", "", tm, sm) if err != nil { diff --git a/pkg/test/logout_test.go b/pkg/test/logout_test.go index fe50cdc5..45d01128 100644 --- a/pkg/test/logout_test.go +++ b/pkg/test/logout_test.go @@ -58,7 +58,7 @@ func TestLogout(t *testing.T) { ens := mock2.NewMockNamespaceManager() // create user - userObject := user.NewUsers(mockClient, ens, logger) + userObject := user.NewUsers(mockClient, ens, 500, 0, logger) sr, err := userObject.CreateNewUserV2("user1", "password1twelve", "", "", tm, sm) if err != nil { t.Fatal(err) diff --git a/pkg/test/ls_test.go b/pkg/test/ls_test.go index 464d4295..096c4234 100644 --- a/pkg/test/ls_test.go +++ b/pkg/test/ls_test.go @@ -53,14 +53,14 @@ func TestPod_ListPods(t *testing.T) { mockClient := bee.NewBeeClient(beeUrl, mock.BatchOkStr, true, logger) acc := account.New(logger) accountInfo := acc.GetUserAccountInfo() - fd := feed.New(accountInfo, mockClient, logger) + fd := feed.New(accountInfo, mockClient, 500, 0, logger) tm := taskmanager.New(1, 10, time.Second*15, logger) defer func() { _ = tm.Stop(context.Background()) }() sm := mock2.NewMockSubscriptionManager() - pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, logger) + pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, 500, 0, logger) _, _, err := acc.CreateUserAccount("") if err != nil { t.Fatal(err) diff --git a/pkg/test/max_pod_test.go b/pkg/test/max_pod_test.go index a16f60dd..7066fa2b 100644 --- a/pkg/test/max_pod_test.go +++ b/pkg/test/max_pod_test.go @@ -39,14 +39,14 @@ func TestMaxPods(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) tm := taskmanager.New(1, 10, time.Second*15, logger) defer func() { _ = tm.Stop(context.Background()) }() sm := mock3.NewMockSubscriptionManager() - pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, logger) + pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, 500, 0, logger) t.Run("create-max-pods", func(t *testing.T) { // t.SkipNow() diff --git a/pkg/test/new_test.go b/pkg/test/new_test.go index 4ed308b0..2a6d4c8e 100644 --- a/pkg/test/new_test.go +++ b/pkg/test/new_test.go @@ -58,7 +58,7 @@ func TestNew(t *testing.T) { ens := mock2.NewMockNamespaceManager() // create user - userObject := user.NewUsers(mockClient, ens, logger) + userObject := user.NewUsers(mockClient, ens, 500, 0, logger) _, err := userObject.CreateNewUserV2("", "password1", "", "", tm, sm) if !errors.Is(err, user.ErrBlankUsername) { t.Fatal(err) @@ -69,7 +69,7 @@ func TestNew(t *testing.T) { ens := mock2.NewMockNamespaceManager() // create user - userObject := user.NewUsers(mockClient, ens, logger) + userObject := user.NewUsers(mockClient, ens, 500, 0, logger) _, err := userObject.CreateNewUserV2("user1", "password1", "", "", tm, sm) if err != nil && !errors.Is(err, user.ErrPasswordTooSmall) { t.Fatal(err) @@ -112,7 +112,7 @@ func TestNew(t *testing.T) { ens := mock2.NewMockNamespaceManager() user1 := "multicredtester" // create user - userObject := user.NewUsers(mockClient, ens, logger) + userObject := user.NewUsers(mockClient, ens, 500, 0, logger) pass := "password1password1" sr, err := userObject.CreateNewUserV2(user1, pass, "", "", tm, sm) if err != nil { diff --git a/pkg/test/open_test.go b/pkg/test/open_test.go index ab318f17..dd2f3214 100644 --- a/pkg/test/open_test.go +++ b/pkg/test/open_test.go @@ -65,8 +65,8 @@ func TestOpen(t *testing.T) { }() sm := mock2.NewMockSubscriptionManager() - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) - pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) + pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, 500, 0, logger) podName1 := "test1" podName2 := "test2" diff --git a/pkg/test/pod_new_test.go b/pkg/test/pod_new_test.go index 66e11108..b9ba9337 100644 --- a/pkg/test/pod_new_test.go +++ b/pkg/test/pod_new_test.go @@ -57,14 +57,14 @@ func TestPodNew(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) tm := taskmanager.New(1, 10, time.Second*15, logger) defer func() { _ = tm.Stop(context.Background()) }() sm := mock2.NewMockSubscriptionManager() - pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, logger) + pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, 500, 0, logger) podName1 := "test1" podName2 := "test2" diff --git a/pkg/test/pod_sharing_test.go b/pkg/test/pod_sharing_test.go index 510570f2..2a341cdf 100644 --- a/pkg/test/pod_sharing_test.go +++ b/pkg/test/pod_sharing_test.go @@ -57,14 +57,14 @@ func TestShare(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) tm := taskmanager.New(1, 10, time.Second*15, logger) defer func() { _ = tm.Stop(context.Background()) }() sm := mock2.NewMockSubscriptionManager() - pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, logger) + pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, 500, 0, logger) podName1 := "test1" acc2 := account.New(logger) @@ -72,8 +72,8 @@ func TestShare(t *testing.T) { if err != nil { t.Fatal(err) } - fd2 := feed.New(acc2.GetUserAccountInfo(), mockClient, logger) - pod2 := pod.NewPod(mockClient, fd2, acc2, tm, sm, logger) + fd2 := feed.New(acc2.GetUserAccountInfo(), mockClient, 500, 0, logger) + pod2 := pod.NewPod(mockClient, fd2, acc2, tm, sm, 500, 0, logger) podName2 := "test2" acc3 := account.New(logger) @@ -81,8 +81,8 @@ func TestShare(t *testing.T) { if err != nil { t.Fatal(err) } - fd3 := feed.New(acc3.GetUserAccountInfo(), mockClient, logger) - pod3 := pod.NewPod(mockClient, fd3, acc3, tm, sm, logger) + fd3 := feed.New(acc3.GetUserAccountInfo(), mockClient, 500, 0, logger) + pod3 := pod.NewPod(mockClient, fd3, acc3, tm, sm, 500, 0, logger) podName3 := "test3" acc4 := account.New(logger) @@ -90,8 +90,8 @@ func TestShare(t *testing.T) { if err != nil { t.Fatal(err) } - fd4 := feed.New(acc4.GetUserAccountInfo(), mockClient, logger) - pod4 := pod.NewPod(mockClient, fd4, acc4, tm, sm, logger) + fd4 := feed.New(acc4.GetUserAccountInfo(), mockClient, 500, 0, logger) + pod4 := pod.NewPod(mockClient, fd4, acc4, tm, sm, 500, 0, logger) podName4 := "test4" acc5 := account.New(logger) @@ -99,8 +99,8 @@ func TestShare(t *testing.T) { if err != nil { t.Fatal(err) } - fd5 := feed.New(acc5.GetUserAccountInfo(), mockClient, logger) - pod5 := pod.NewPod(mockClient, fd5, acc5, tm, sm, logger) + fd5 := feed.New(acc5.GetUserAccountInfo(), mockClient, 500, 0, logger) + pod5 := pod.NewPod(mockClient, fd5, acc5, tm, sm, 500, 0, logger) podName5 := "test5" acc6 := account.New(logger) @@ -108,8 +108,8 @@ func TestShare(t *testing.T) { if err != nil { t.Fatal(err) } - fd6 := feed.New(acc6.GetUserAccountInfo(), mockClient, logger) - pod6 := pod.NewPod(mockClient, fd6, acc6, tm, sm, logger) + fd6 := feed.New(acc6.GetUserAccountInfo(), mockClient, 500, 0, logger) + pod6 := pod.NewPod(mockClient, fd6, acc6, tm, sm, 500, 0, logger) podName6 := "test6" t.Run("share-pod", func(t *testing.T) { @@ -433,8 +433,8 @@ func TestShare(t *testing.T) { if err != nil { t.Fatal(err) } - fd7 := feed.New(acc7.GetUserAccountInfo(), mockClient, logger) - pod7 := pod.NewPod(mockClient, fd7, acc7, tm, sm, logger) + fd7 := feed.New(acc7.GetUserAccountInfo(), mockClient, 500, 0, logger) + pod7 := pod.NewPod(mockClient, fd7, acc7, tm, sm, 500, 0, logger) podName7 := "test7" acc8 := account.New(logger) @@ -442,8 +442,8 @@ func TestShare(t *testing.T) { if err != nil { t.Fatal(err) } - fd8 := feed.New(acc8.GetUserAccountInfo(), mockClient, logger) - pod8 := pod.NewPod(mockClient, fd8, acc8, tm, sm, logger) + fd8 := feed.New(acc8.GetUserAccountInfo(), mockClient, 500, 0, logger) + pod8 := pod.NewPod(mockClient, fd8, acc8, tm, sm, 500, 0, logger) // create sending pod and receiving pod podPassword, _ := utils.GetRandString(pod.PasswordLength) diff --git a/pkg/test/pod_stat_test.go b/pkg/test/pod_stat_test.go index c5e54a92..fbc9c12d 100644 --- a/pkg/test/pod_stat_test.go +++ b/pkg/test/pod_stat_test.go @@ -56,14 +56,14 @@ func TestStat(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) tm := taskmanager.New(1, 10, time.Second*15, logger) defer func() { _ = tm.Stop(context.Background()) }() sm := mock3.NewMockSubscriptionManager() - pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, logger) + pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, 500, 0, logger) podName1 := "test1" t.Run("pod-stat", func(t *testing.T) { diff --git a/pkg/test/stat_test.go b/pkg/test/stat_test.go index e5549b49..a6342b58 100644 --- a/pkg/test/stat_test.go +++ b/pkg/test/stat_test.go @@ -58,7 +58,7 @@ func TestUserStat(t *testing.T) { t.Run("stat-nonexistent-user", func(t *testing.T) { ens := mock2.NewMockNamespaceManager() // create user - userObject := user.NewUsers(mockClient, ens, logger) + userObject := user.NewUsers(mockClient, ens, 500, 0, logger) ui := &user.Info{} // stat the user _, err := userObject.GetUserStat(ui) @@ -70,7 +70,7 @@ func TestUserStat(t *testing.T) { t.Run("stat-user", func(t *testing.T) { ens := mock2.NewMockNamespaceManager() // create user - userObject := user.NewUsers(mockClient, ens, logger) + userObject := user.NewUsers(mockClient, ens, 500, 0, logger) sr, err := userObject.CreateNewUserV2("user1", "password1twelve", "", "", tm, sm) if err != nil { t.Fatal(err) diff --git a/pkg/test/subscription_test.go b/pkg/test/subscription_test.go index 5a69b4ae..5bc7ce17 100644 --- a/pkg/test/subscription_test.go +++ b/pkg/test/subscription_test.go @@ -41,7 +41,7 @@ func TestSubscription(t *testing.T) { if err != nil { t.Fatal(err) } - fd := feed.New(acc1.GetUserAccountInfo(), mockClient, logger) + fd := feed.New(acc1.GetUserAccountInfo(), mockClient, 500, 0, logger) tm := taskmanager.New(1, 10, time.Second*15, logger) defer func() { _ = tm.Stop(context.Background()) @@ -54,7 +54,7 @@ func TestSubscription(t *testing.T) { } sm := mock2.NewMockSubscriptionManager() - pod1 := pod.NewPod(mockClient, fd, acc1, tm, sm, logger) + pod1 := pod.NewPod(mockClient, fd, acc1, tm, sm, 500, 0, logger) randomLongPodName1, err := utils.GetRandString(64) if err != nil { @@ -97,8 +97,8 @@ func TestSubscription(t *testing.T) { t.Fatal(err) } - fd2 := feed.New(acc2.GetUserAccountInfo(), mockClient, logger) - pod2 := pod.NewPod(mockClient, fd2, acc2, tm, sm, logger) + fd2 := feed.New(acc2.GetUserAccountInfo(), mockClient, 500, 0, logger) + pod2 := pod.NewPod(mockClient, fd2, acc2, tm, sm, 500, 0, logger) a2 := acc2.GetUserAccountInfo().GetAddress() addr2 := common.HexToAddress(a2.Hex()) nameHash2, err := goens.NameHash(addr2.Hex()) diff --git a/pkg/test/sync_test.go b/pkg/test/sync_test.go index d7dc766d..a7acc204 100644 --- a/pkg/test/sync_test.go +++ b/pkg/test/sync_test.go @@ -61,8 +61,8 @@ func TestSync(t *testing.T) { }() sm := mock2.NewMockSubscriptionManager() - fd := feed.New(acc.GetUserAccountInfo(), mockClient, logger) - pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, logger) + fd := feed.New(acc.GetUserAccountInfo(), mockClient, 500, 0, logger) + pod1 := pod.NewPod(mockClient, fd, acc, tm, sm, 500, 0, logger) podName1 := "test1" t.Run("sync-pod", func(t *testing.T) { diff --git a/pkg/test/user_sharing_test.go b/pkg/test/user_sharing_test.go index 2c01f741..618eab76 100644 --- a/pkg/test/user_sharing_test.go +++ b/pkg/test/user_sharing_test.go @@ -70,8 +70,8 @@ func TestSharing(t *testing.T) { }() sm := mock3.NewMockSubscriptionManager() - fd1 := feed.New(acc1.GetUserAccountInfo(), mockClient, logger) - pod1 := pod.NewPod(mockClient, fd1, acc1, tm, sm, logger) + fd1 := feed.New(acc1.GetUserAccountInfo(), mockClient, 500, 0, logger) + pod1 := pod.NewPod(mockClient, fd1, acc1, tm, sm, 500, 0, logger) podName1 := "test1" acc2 := account.New(logger) @@ -83,14 +83,14 @@ func TestSharing(t *testing.T) { if err != nil { t.Fatal(err) } - fd2 := feed.New(acc2.GetUserAccountInfo(), mockClient, logger) - pod2 := pod.NewPod(mockClient, fd2, acc2, tm, sm, logger) + fd2 := feed.New(acc2.GetUserAccountInfo(), mockClient, 500, 0, logger) + pod2 := pod.NewPod(mockClient, fd2, acc2, tm, sm, 500, 0, logger) podName2 := "test2" t.Run("sharing-user", func(t *testing.T) { ens := mock2.NewMockNamespaceManager() // create source user - userObject1 := user.NewUsers(mockClient, ens, logger) + userObject1 := user.NewUsers(mockClient, ens, 500, 0, logger) sr0, err := userObject1.CreateNewUserV2("user1", "password1twelve", "", "", tm, sm) if err != nil { t.Fatal(err) @@ -131,7 +131,7 @@ func TestSharing(t *testing.T) { } // create destination user - userObject2 := user.NewUsers(mockClient, ens, logger) + userObject2 := user.NewUsers(mockClient, ens, 500, 0, logger) sr, err := userObject2.CreateNewUserV2("user2", "password1twelve", "", "", tm, sm) if err != nil { t.Fatal(err) diff --git a/pkg/user/lite.go b/pkg/user/lite.go index 2e9c3583..f0a0246c 100644 --- a/pkg/user/lite.go +++ b/pkg/user/lite.go @@ -25,7 +25,7 @@ func (u *Users) LoadLiteUser(userName, _, mnemonic, sessionId string, tm taskman acc := account.New(u.logger) accountInfo := acc.GetUserAccountInfo() - fd := feed.New(accountInfo, u.client, u.logger) + fd := feed.New(accountInfo, u.client, u.feedCacheSize, u.feedCacheTTL, u.logger) // create a new base user account with the mnemonic mnemonic, _, err := acc.CreateUserAccount(mnemonic) if err != nil { // skipcq: TCV-001 @@ -35,7 +35,7 @@ func (u *Users) LoadLiteUser(userName, _, mnemonic, sessionId string, tm taskman // Instantiate pod, dir & file objects file := f.NewFile(userName, u.client, fd, accountInfo.GetAddress(), tm, u.logger) dir := d.NewDirectory(userName, u.client, fd, accountInfo.GetAddress(), file, tm, u.logger) - pod := p.NewPod(u.client, fd, acc, tm, sm, u.logger) + pod := p.NewPod(u.client, fd, acc, tm, sm, u.feedCacheSize, u.feedCacheTTL, u.logger) if sessionId == "" { sessionId = auth.GetUniqueSessionId() } diff --git a/pkg/user/login.go b/pkg/user/login.go index 51ee63aa..73003521 100644 --- a/pkg/user/login.go +++ b/pkg/user/login.go @@ -66,7 +66,7 @@ func (u *Users) LoginUserV2(userName, passPhrase string, client blockstore.Clien acc := account.New(u.logger) accountInfo := acc.GetUserAccountInfo() // load encrypted private key - fd := feed.New(accountInfo, client, u.logger) + fd := feed.New(accountInfo, client, u.feedCacheSize, u.feedCacheTTL, u.logger) key, err := u.downloadPortableAccount(utils.Address(address), userName, passPhrase, fd) if err != nil { return nil, ErrInvalidPassword @@ -101,7 +101,7 @@ func (u *Users) LoginUserV2(userName, passPhrase string, client blockstore.Clien // Instantiate pod, dir & file objects file := f.NewFile(userName, client, fd, accountInfo.GetAddress(), tm, u.logger) - pod := p.NewPod(u.client, fd, acc, tm, sm, u.logger) + pod := p.NewPod(u.client, fd, acc, tm, sm, u.feedCacheSize, u.feedCacheTTL, u.logger) dir := d.NewDirectory(userName, client, fd, accountInfo.GetAddress(), file, tm, u.logger) if sessionId == "" { sessionId = auth.GetUniqueSessionId() @@ -191,7 +191,7 @@ func (u *Users) ConnectWallet(userName, passPhrase, walletAddressHex, signature acc := account.New(u.logger) accountInfo := acc.GetUserAccountInfo() // load encrypted private key - fd := feed.New(accountInfo, client, u.logger) + fd := feed.New(accountInfo, client, u.feedCacheSize, u.feedCacheTTL, u.logger) key, err := u.downloadPortableAccount(utils.Address(address), userName, passPhrase, fd) if err != nil { u.logger.Errorf(err.Error()) @@ -224,7 +224,7 @@ func (u *Users) LoginWithWallet(addressHex, signature string, client blockstore. acc := account.New(u.logger) accountInfo := acc.GetUserAccountInfo() // load encrypted private key - fd := feed.New(accountInfo, client, u.logger) + fd := feed.New(accountInfo, client, u.feedCacheSize, u.feedCacheTTL, u.logger) key, err := u.downloadPortableAccount(utils.Address(address), addressHex, signature, fd) if err != nil { u.logger.Errorf(err.Error()) @@ -253,7 +253,7 @@ func (u *Users) LoginWithWallet(addressHex, signature string, client blockstore. // Instantiate pod, dir & file objects file := f.NewFile(addressHex, client, fd, accountInfo.GetAddress(), tm, u.logger) - pod := p.NewPod(u.client, fd, acc, tm, sm, u.logger) + pod := p.NewPod(u.client, fd, acc, tm, sm, u.feedCacheSize, u.feedCacheTTL, u.logger) dir := d.NewDirectory(addressHex, client, fd, accountInfo.GetAddress(), file, tm, u.logger) if sessionId == "" { sessionId = auth.GetUniqueSessionId() diff --git a/pkg/user/new.go b/pkg/user/new.go index 08ec3610..d7a6edab 100644 --- a/pkg/user/new.go +++ b/pkg/user/new.go @@ -78,7 +78,7 @@ func (u *Users) CreateNewUserV2(userName, passPhrase, mnemonic, sessionId string acc := account.New(u.logger) accountInfo := acc.GetUserAccountInfo() - fd := feed.New(accountInfo, u.client, u.logger) + fd := feed.New(accountInfo, u.client, u.feedCacheSize, u.feedCacheTTL, u.logger) // create a new base user account with the mnemonic mnemonic, seed, err := acc.CreateUserAccount(mnemonic) @@ -124,7 +124,7 @@ func (u *Users) CreateNewUserV2(userName, passPhrase, mnemonic, sessionId string // Instantiate pod, dir & file objects file := f.NewFile(userName, u.client, fd, accountInfo.GetAddress(), tm, u.logger) dir := d.NewDirectory(userName, u.client, fd, accountInfo.GetAddress(), file, tm, u.logger) - pod := p.NewPod(u.client, fd, acc, tm, sm, u.logger) + pod := p.NewPod(u.client, fd, acc, tm, sm, u.feedCacheSize, u.feedCacheTTL, u.logger) if sessionId == "" { sessionId = auth.GetUniqueSessionId() } diff --git a/pkg/user/users.go b/pkg/user/users.go index c67fcb71..26db1ec4 100644 --- a/pkg/user/users.go +++ b/pkg/user/users.go @@ -18,6 +18,7 @@ package user import ( "sync" + "time" "github.com/fairdatasociety/fairOS-dfs/pkg/blockstore" "github.com/fairdatasociety/fairOS-dfs/pkg/ensm" @@ -31,17 +32,22 @@ type Users struct { userMu *sync.RWMutex logger logging.Logger ens ensm.ENSManager + + feedCacheSize int + feedCacheTTL time.Duration } // NewUsers creates the main user object which stores all the logged-in users and there respective // other data structures. -func NewUsers(client blockstore.Client, ens ensm.ENSManager, logger logging.Logger) *Users { +func NewUsers(client blockstore.Client, ens ensm.ENSManager, feedCacheSize int, feedCacheTTL time.Duration, logger logging.Logger) *Users { return &Users{ - client: client, - userMap: make(map[string]*Info), - userMu: &sync.RWMutex{}, - logger: logger, - ens: ens, + client: client, + userMap: make(map[string]*Info), + userMu: &sync.RWMutex{}, + logger: logger, + ens: ens, + feedCacheSize: feedCacheSize, + feedCacheTTL: feedCacheTTL, } }