diff --git a/server/services/store/mockstore/mockstore.go b/server/services/store/mockstore/mockstore.go index 462b401a7..6a1bc3634 100644 --- a/server/services/store/mockstore/mockstore.go +++ b/server/services/store/mockstore/mockstore.go @@ -730,21 +730,6 @@ func (mr *MockStoreMockRecorder) GetSubTree2(arg0, arg1, arg2 interface{}) *gomo return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubTree2", reflect.TypeOf((*MockStore)(nil).GetSubTree2), arg0, arg1, arg2) } -// GetSubTree3 mocks base method. -func (m *MockStore) GetSubTree3(arg0, arg1 string, arg2 model.QuerySubtreeOptions) ([]model.Block, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSubTree3", arg0, arg1, arg2) - ret0, _ := ret[0].([]model.Block) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetSubTree3 indicates an expected call of GetSubTree3. -func (mr *MockStoreMockRecorder) GetSubTree3(arg0, arg1, arg2 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubTree3", reflect.TypeOf((*MockStore)(nil).GetSubTree3), arg0, arg1, arg2) -} - // GetSubscribersCountForBlock mocks base method. func (m *MockStore) GetSubscribersCountForBlock(arg0 string) (int, error) { m.ctrl.T.Helper() diff --git a/server/services/store/sqlstore/blocks.go b/server/services/store/sqlstore/blocks.go index 23ccaa072..a79ddfda0 100644 --- a/server/services/store/sqlstore/blocks.go +++ b/server/services/store/sqlstore/blocks.go @@ -168,60 +168,6 @@ func (s *SQLStore) getSubTree2(db sq.BaseRunner, boardID string, blockID string, return s.blocksFromRows(rows) } -// getSubTree3 returns blocks within 3 levels of the given blockID. -func (s *SQLStore) getSubTree3(db sq.BaseRunner, boardID string, blockID string, opts model.QuerySubtreeOptions) ([]model.Block, error) { - // This first subquery returns repeated blocks - query := s.getQueryBuilder(db).Select( - "l3.id", - "l3.parent_id", - "l3.created_by", - "l3.modified_by", - "l3."+s.escapeField("schema"), - "l3.type", - "l3.title", - "l3.fields", - s.timestampToCharField("l3.insert_at", "insertAt"), - "l3.create_at", - "l3.update_at", - "l3.delete_at", - "l3.board_id", - ). - From(s.tablePrefix + "blocks" + " as l1"). - Join(s.tablePrefix + "blocks" + " as l2 on l2.parent_id = l1.id or l2.id = l1.id"). - Join(s.tablePrefix + "blocks" + " as l3 on l3.parent_id = l2.id or l3.id = l2.id"). - Where(sq.Eq{"l1.id": blockID}). - Where(sq.Eq{"l3.board_id": boardID}). - OrderBy("insertAt,l3.id") - - if opts.BeforeUpdateAt != 0 { - query = query.Where(sq.LtOrEq{"update_at": opts.BeforeUpdateAt}) - } - - if opts.AfterUpdateAt != 0 { - query = query.Where(sq.GtOrEq{"update_at": opts.AfterUpdateAt}) - } - - if s.dbType == model.PostgresDBType { - query = query.Options("DISTINCT ON (insertAt,l3.id)") - } else { - query = query.Distinct() - } - - if opts.Limit != 0 { - query = query.Limit(opts.Limit) - } - - rows, err := query.Query() - if err != nil { - s.logger.Error(`getSubTree3 ERROR`, mlog.Err(err)) - - return nil, err - } - defer s.CloseRows(rows) - - return s.blocksFromRows(rows) -} - func (s *SQLStore) getBlocksForBoard(db sq.BaseRunner, boardID string) ([]model.Block, error) { query := s.getQueryBuilder(db). Select(s.blockFields()...). @@ -799,7 +745,7 @@ func (s *SQLStore) replaceBlockID(db sq.BaseRunner, currentID, newID, workspaceI } func (s *SQLStore) duplicateBlock(db sq.BaseRunner, boardID string, blockID string, userID string, asTemplate bool) ([]model.Block, error) { - blocks, err := s.getSubTree3(db, boardID, blockID, model.QuerySubtreeOptions{}) + blocks, err := s.getSubTree2(db, boardID, blockID, model.QuerySubtreeOptions{}) if err != nil { return nil, err } diff --git a/server/services/store/sqlstore/public_methods.go b/server/services/store/sqlstore/public_methods.go index a3f30591b..79846efeb 100644 --- a/server/services/store/sqlstore/public_methods.go +++ b/server/services/store/sqlstore/public_methods.go @@ -385,11 +385,6 @@ func (s *SQLStore) GetSubTree2(boardID string, blockID string, opts model.QueryS } -func (s *SQLStore) GetSubTree3(boardID string, blockID string, opts model.QuerySubtreeOptions) ([]model.Block, error) { - return s.getSubTree3(s.db, boardID, blockID, opts) - -} - func (s *SQLStore) GetSubscribersCountForBlock(blockID string) (int, error) { return s.getSubscribersCountForBlock(s.db, blockID) diff --git a/server/services/store/store.go b/server/services/store/store.go index 666a4c32f..e8ea5ede7 100644 --- a/server/services/store/store.go +++ b/server/services/store/store.go @@ -18,7 +18,6 @@ type Store interface { GetBlocksWithBoardID(boardID string) ([]model.Block, error) GetBlocksWithType(boardID, blockType string) ([]model.Block, error) GetSubTree2(boardID, blockID string, opts model.QuerySubtreeOptions) ([]model.Block, error) - GetSubTree3(boardID, blockID string, opts model.QuerySubtreeOptions) ([]model.Block, error) GetBlocksForBoard(boardID string) ([]model.Block, error) // @withTransaction InsertBlock(block *model.Block, userID string) error diff --git a/server/services/store/storetests/blocks.go b/server/services/store/storetests/blocks.go index c87dd3ce1..f8db456e4 100644 --- a/server/services/store/storetests/blocks.go +++ b/server/services/store/storetests/blocks.go @@ -18,7 +18,6 @@ const ( testBoardID = "board-id" ) -//nolint:dupl func StoreTestBlocksStore(t *testing.T, setup func(t *testing.T) (store.Store, func())) { t.Run("InsertBlock", func(t *testing.T) { store, tearDown := setup(t) @@ -55,11 +54,6 @@ func StoreTestBlocksStore(t *testing.T, setup func(t *testing.T) (store.Store, f defer tearDown() testGetSubTree2(t, store) }) - t.Run("GetSubTree3", func(t *testing.T) { - store, tearDown := setup(t) - defer tearDown() - testGetSubTree3(t, store) - }) t.Run("GetBlocks", func(t *testing.T) { store, tearDown := setup(t) defer tearDown() @@ -512,47 +506,6 @@ func testGetSubTree2(t *testing.T, store store.Store) { }) } -func testGetSubTree3(t *testing.T, store store.Store) { - boardID := testBoardID - blocks, err := store.GetBlocksForBoard(boardID) - require.NoError(t, err) - initialCount := len(blocks) - - InsertBlocks(t, store, subtreeSampleBlocks, "user-id-1") - time.Sleep(1 * time.Millisecond) - defer DeleteBlocks(t, store, subtreeSampleBlocks, "test") - - blocks, err = store.GetBlocksForBoard(boardID) - require.NoError(t, err) - require.Len(t, blocks, initialCount+6) - - t.Run("from board id", func(t *testing.T) { - blocks, err = store.GetSubTree3(boardID, "parent", model.QuerySubtreeOptions{}) - require.NoError(t, err) - require.Len(t, blocks, 5) - require.True(t, ContainsBlockWithID(blocks, "parent")) - require.True(t, ContainsBlockWithID(blocks, "child1")) - require.True(t, ContainsBlockWithID(blocks, "child2")) - require.True(t, ContainsBlockWithID(blocks, "grandchild1")) - require.True(t, ContainsBlockWithID(blocks, "grandchild2")) - }) - - t.Run("from child id", func(t *testing.T) { - blocks, err = store.GetSubTree3(boardID, "child1", model.QuerySubtreeOptions{}) - require.NoError(t, err) - require.Len(t, blocks, 3) - require.True(t, ContainsBlockWithID(blocks, "child1")) - require.True(t, ContainsBlockWithID(blocks, "grandchild1")) - require.True(t, ContainsBlockWithID(blocks, "greatgrandchild1")) - }) - - t.Run("from not existing id", func(t *testing.T) { - blocks, err = store.GetSubTree3(boardID, "not-exists", model.QuerySubtreeOptions{}) - require.NoError(t, err) - require.Len(t, blocks, 0) - }) -} - func testDeleteBlock(t *testing.T, store store.Store) { userID := testUserID boardID := testBoardID @@ -849,14 +802,14 @@ func testDuplicateBlock(t *testing.T, store store.Store) { t.Run("duplicate existing block as no template", func(t *testing.T) { blocks, err := store.DuplicateBlock(testBoardID, "child1", testUserID, false) require.NoError(t, err) - require.Len(t, blocks, 3) + require.Len(t, blocks, 2) require.Equal(t, false, blocks[0].Fields["isTemplate"]) }) t.Run("duplicate existing block as template", func(t *testing.T) { blocks, err := store.DuplicateBlock(testBoardID, "child1", testUserID, true) require.NoError(t, err) - require.Len(t, blocks, 3) + require.Len(t, blocks, 2) require.Equal(t, true, blocks[0].Fields["isTemplate"]) }) diff --git a/server/services/store/storetests/boards.go b/server/services/store/storetests/boards.go index e00d71148..5de60f8d6 100644 --- a/server/services/store/storetests/boards.go +++ b/server/services/store/storetests/boards.go @@ -12,7 +12,6 @@ import ( "github.com/stretchr/testify/require" ) -//nolint:dupl func StoreTestBoardStore(t *testing.T, setup func(t *testing.T) (store.Store, func())) { t.Run("GetBoard", func(t *testing.T) { store, tearDown := setup(t) diff --git a/webapp/src/components/boardTemplateSelector/boardTemplateSelectorItem.test.tsx b/webapp/src/components/boardTemplateSelector/boardTemplateSelectorItem.test.tsx index 116aef95b..3acfaf589 100644 --- a/webapp/src/components/boardTemplateSelector/boardTemplateSelectorItem.test.tsx +++ b/webapp/src/components/boardTemplateSelector/boardTemplateSelectorItem.test.tsx @@ -38,47 +38,6 @@ const groupProperty: IPropertyTemplate = { ], } -jest.mock('../../octoClient', () => { - return { - getSubtree: jest.fn(() => Promise.resolve([ - { - id: '1', - teamId: 'team', - title: 'Template', - icon: '🚴🏻‍♂️', - cardProperties: [groupProperty], - dateDisplayPropertyId: 'id-5', - }, - { - id: '2', - boardId: '1', - title: 'View', - type: 'view', - fields: { - groupById: 'group-prop-id', - viewType: 'board', - visibleOptionIds: ['group-prop-id'], - hiddenOptionIds: [], - visiblePropertyIds: ['group-prop-id'], - sortOptions: [], - kanbanCalculations: {}, - }, - }, - { - id: '3', - boardId: '1', - title: 'Card', - type: 'card', - fields: { - icon: '🚴🏻‍♂️', - properties: { - 'group-prop-id': 'test', - }, - }, - }, - ])), - } -}) jest.mock('../../utils') jest.mock('../../mutator')