Remove redundant store APIs for Boards: (#22968)
- getBlocksWithParent - getBlocksWithParentAndType - getBlocksWithType - getBlocksForBoard
Этот коммит содержится в:
@@ -72,7 +72,6 @@ func (a *API) handleGetBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
query := r.URL.Query()
|
||||
parentID := query.Get("parent_id")
|
||||
blockType := query.Get("type")
|
||||
all := query.Get("all")
|
||||
blockID := query.Get("block_id")
|
||||
boardID := mux.Vars(r)["boardID"]
|
||||
|
||||
@@ -122,18 +121,11 @@ func (a *API) handleGetBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
auditRec.AddMeta("parentID", parentID)
|
||||
auditRec.AddMeta("blockType", blockType)
|
||||
auditRec.AddMeta("all", all)
|
||||
auditRec.AddMeta("blockID", blockID)
|
||||
|
||||
var blocks []*model.Block
|
||||
var block *model.Block
|
||||
switch {
|
||||
case all != "":
|
||||
blocks, err = a.app.GetBlocksForBoard(boardID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r, err)
|
||||
return
|
||||
}
|
||||
case blockID != "":
|
||||
block, err = a.app.GetBlockByID(blockID)
|
||||
if err != nil {
|
||||
@@ -148,7 +140,12 @@ func (a *API) handleGetBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
blocks = append(blocks, block)
|
||||
default:
|
||||
blocks, err = a.app.GetBlocks(boardID, parentID, blockType)
|
||||
opts := model.QueryBlocksOptions{
|
||||
BoardID: boardID,
|
||||
ParentID: parentID,
|
||||
BlockType: model.BlockType(blockType),
|
||||
}
|
||||
blocks, err = a.app.GetBlocks(opts)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r, err)
|
||||
return
|
||||
|
||||
@@ -18,20 +18,11 @@ import (
|
||||
|
||||
var ErrBlocksFromMultipleBoards = errors.New("the block set contain blocks from multiple boards")
|
||||
|
||||
func (a *App) GetBlocks(boardID, parentID string, blockType string) ([]*model.Block, error) {
|
||||
if boardID == "" {
|
||||
func (a *App) GetBlocks(opts model.QueryBlocksOptions) ([]*model.Block, error) {
|
||||
if opts.BoardID == "" {
|
||||
return []*model.Block{}, nil
|
||||
}
|
||||
|
||||
if blockType != "" && parentID != "" {
|
||||
return a.store.GetBlocksWithParentAndType(boardID, parentID, blockType)
|
||||
}
|
||||
|
||||
if blockType != "" {
|
||||
return a.store.GetBlocksWithType(boardID, blockType)
|
||||
}
|
||||
|
||||
return a.store.GetBlocksWithParent(boardID, parentID)
|
||||
return a.store.GetBlocks(opts)
|
||||
}
|
||||
|
||||
func (a *App) DuplicateBlock(boardID string, blockID string, userID string, asTemplate bool) ([]*model.Block, error) {
|
||||
@@ -514,10 +505,6 @@ func (a *App) GetBlockCountsByType() (map[string]int64, error) {
|
||||
return a.store.GetBlockCountsByType()
|
||||
}
|
||||
|
||||
func (a *App) GetBlocksForBoard(boardID string) ([]*model.Block, error) {
|
||||
return a.store.GetBlocksForBoard(boardID)
|
||||
}
|
||||
|
||||
func (a *App) notifyBlockChanged(action notify.Action, block *model.Block, oldBlock *model.Block, modifiedByID string) {
|
||||
// don't notify if notifications service disabled, or block change is generated via system user.
|
||||
if a.notifications == nil || modifiedByID == model.SystemUserID {
|
||||
|
||||
@@ -207,10 +207,17 @@ func TestIsWithinViewsLimit(t *testing.T) {
|
||||
Views: mm_model.NewInt(2),
|
||||
},
|
||||
}
|
||||
|
||||
opts := model.QueryBlocksOptions{
|
||||
BoardID: "board_id",
|
||||
ParentID: "parent_id",
|
||||
BlockType: model.BlockType("view"),
|
||||
}
|
||||
|
||||
th.Store.EXPECT().GetCloudLimits().Return(cloudLimit, nil)
|
||||
th.Store.EXPECT().GetUsedCardsCount().Return(1, nil)
|
||||
th.Store.EXPECT().GetCardLimitTimestamp().Return(int64(1), nil)
|
||||
th.Store.EXPECT().GetBlocksWithParentAndType("board_id", "parent_id", "view").Return([]*model.Block{{}}, nil)
|
||||
th.Store.EXPECT().GetBlocks(opts).Return([]*model.Block{{}}, nil)
|
||||
|
||||
withinLimits, err := th.App.isWithinViewsLimit("board_id", &model.Block{ParentID: "parent_id"})
|
||||
assert.NoError(t, err)
|
||||
@@ -225,10 +232,17 @@ func TestIsWithinViewsLimit(t *testing.T) {
|
||||
Views: mm_model.NewInt(1),
|
||||
},
|
||||
}
|
||||
|
||||
opts := model.QueryBlocksOptions{
|
||||
BoardID: "board_id",
|
||||
ParentID: "parent_id",
|
||||
BlockType: model.BlockType("view"),
|
||||
}
|
||||
|
||||
th.Store.EXPECT().GetCloudLimits().Return(cloudLimit, nil)
|
||||
th.Store.EXPECT().GetUsedCardsCount().Return(1, nil)
|
||||
th.Store.EXPECT().GetCardLimitTimestamp().Return(int64(1), nil)
|
||||
th.Store.EXPECT().GetBlocksWithParentAndType("board_id", "parent_id", "view").Return([]*model.Block{{}}, nil)
|
||||
th.Store.EXPECT().GetBlocks(opts).Return([]*model.Block{{}}, nil)
|
||||
|
||||
withinLimits, err := th.App.isWithinViewsLimit("board_id", &model.Block{ParentID: "parent_id"})
|
||||
assert.NoError(t, err)
|
||||
@@ -243,10 +257,17 @@ func TestIsWithinViewsLimit(t *testing.T) {
|
||||
Views: mm_model.NewInt(2),
|
||||
},
|
||||
}
|
||||
|
||||
opts := model.QueryBlocksOptions{
|
||||
BoardID: "board_id",
|
||||
ParentID: "parent_id",
|
||||
BlockType: model.BlockType("view"),
|
||||
}
|
||||
|
||||
th.Store.EXPECT().GetCloudLimits().Return(cloudLimit, nil)
|
||||
th.Store.EXPECT().GetUsedCardsCount().Return(1, nil)
|
||||
th.Store.EXPECT().GetCardLimitTimestamp().Return(int64(1), nil)
|
||||
th.Store.EXPECT().GetBlocksWithParentAndType("board_id", "parent_id", "view").Return([]*model.Block{{}, {}, {}}, nil)
|
||||
th.Store.EXPECT().GetBlocks(opts).Return([]*model.Block{{}, {}, {}}, nil)
|
||||
|
||||
withinLimits, err := th.App.isWithinViewsLimit("board_id", &model.Block{ParentID: "parent_id"})
|
||||
assert.NoError(t, err)
|
||||
@@ -261,10 +282,17 @@ func TestIsWithinViewsLimit(t *testing.T) {
|
||||
Views: mm_model.NewInt(2),
|
||||
},
|
||||
}
|
||||
|
||||
opts := model.QueryBlocksOptions{
|
||||
BoardID: "board_id",
|
||||
ParentID: "parent_id",
|
||||
BlockType: model.BlockType("view"),
|
||||
}
|
||||
|
||||
th.Store.EXPECT().GetCloudLimits().Return(cloudLimit, nil)
|
||||
th.Store.EXPECT().GetUsedCardsCount().Return(1, nil)
|
||||
th.Store.EXPECT().GetCardLimitTimestamp().Return(int64(1), nil)
|
||||
th.Store.EXPECT().GetBlocksWithParentAndType("board_id", "parent_id", "view").Return([]*model.Block{}, nil)
|
||||
th.Store.EXPECT().GetBlocks(opts).Return([]*model.Block{}, nil)
|
||||
|
||||
withinLimits, err := th.App.isWithinViewsLimit("board_id", &model.Block{ParentID: "parent_id"})
|
||||
assert.NoError(t, err)
|
||||
@@ -333,10 +361,17 @@ func TestInsertBlocks(t *testing.T) {
|
||||
Views: mm_model.NewInt(2),
|
||||
},
|
||||
}
|
||||
|
||||
opts := model.QueryBlocksOptions{
|
||||
BoardID: "test-board-id",
|
||||
ParentID: "parent_id",
|
||||
BlockType: model.BlockType("view"),
|
||||
}
|
||||
|
||||
th.Store.EXPECT().GetCloudLimits().Return(cloudLimit, nil)
|
||||
th.Store.EXPECT().GetUsedCardsCount().Return(1, nil)
|
||||
th.Store.EXPECT().GetCardLimitTimestamp().Return(int64(1), nil)
|
||||
th.Store.EXPECT().GetBlocksWithParentAndType("test-board-id", "parent_id", "view").Return([]*model.Block{{}}, nil)
|
||||
th.Store.EXPECT().GetBlocks(opts).Return([]*model.Block{{}}, nil)
|
||||
|
||||
_, err := th.App.InsertBlocks([]*model.Block{block}, "user-id-1")
|
||||
require.NoError(t, err)
|
||||
@@ -365,10 +400,17 @@ func TestInsertBlocks(t *testing.T) {
|
||||
Views: mm_model.NewInt(2),
|
||||
},
|
||||
}
|
||||
|
||||
opts := model.QueryBlocksOptions{
|
||||
BoardID: "test-board-id",
|
||||
ParentID: "parent_id",
|
||||
BlockType: model.BlockType("view"),
|
||||
}
|
||||
|
||||
th.Store.EXPECT().GetCloudLimits().Return(cloudLimit, nil)
|
||||
th.Store.EXPECT().GetUsedCardsCount().Return(1, nil)
|
||||
th.Store.EXPECT().GetCardLimitTimestamp().Return(int64(1), nil)
|
||||
th.Store.EXPECT().GetBlocksWithParentAndType("test-board-id", "parent_id", "view").Return([]*model.Block{{}, {}}, nil)
|
||||
th.Store.EXPECT().GetBlocks(opts).Return([]*model.Block{{}, {}}, nil)
|
||||
|
||||
_, err := th.App.InsertBlocks([]*model.Block{block}, "user-id-1")
|
||||
require.Error(t, err)
|
||||
@@ -406,10 +448,17 @@ func TestInsertBlocks(t *testing.T) {
|
||||
Views: mm_model.NewInt(2),
|
||||
},
|
||||
}
|
||||
|
||||
opts := model.QueryBlocksOptions{
|
||||
BoardID: "test-board-id",
|
||||
ParentID: "parent_id",
|
||||
BlockType: model.BlockType("view"),
|
||||
}
|
||||
|
||||
th.Store.EXPECT().GetCloudLimits().Return(cloudLimit, nil).Times(2)
|
||||
th.Store.EXPECT().GetUsedCardsCount().Return(1, nil).Times(2)
|
||||
th.Store.EXPECT().GetCardLimitTimestamp().Return(int64(1), nil).Times(2)
|
||||
th.Store.EXPECT().GetBlocksWithParentAndType("test-board-id", "parent_id", "view").Return([]*model.Block{{}}, nil).Times(2)
|
||||
th.Store.EXPECT().GetBlocks(opts).Return([]*model.Block{{}}, nil).Times(2)
|
||||
|
||||
_, err := th.App.InsertBlocks([]*model.Block{view1, view2}, "user-id-1")
|
||||
require.Error(t, err)
|
||||
|
||||
@@ -86,7 +86,7 @@ func (a *App) writeArchiveBoard(zw *zip.Writer, board model.Board, opt model.Exp
|
||||
var files []string
|
||||
// write the board's blocks
|
||||
// TODO: paginate this
|
||||
blocks, err := a.GetBlocksForBoard(board.ID)
|
||||
blocks, err := a.GetBlocks(model.QueryBlocksOptions{BoardID: board.ID})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ func TestCreateBoardsAndBlocks(t *testing.T) {
|
||||
require.Equal(t, "public board", board1.Title)
|
||||
require.Equal(t, model.BoardTypeOpen, board1.Type)
|
||||
require.NotEqual(t, "board-id-1", board1.ID)
|
||||
blocks1, err := th.Server.App().GetBlocksForBoard(board1.ID)
|
||||
blocks1, err := th.Server.App().GetBlocks(model.QueryBlocksOptions{BoardID: board1.ID})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, blocks1, 1)
|
||||
require.Equal(t, "block 1", blocks1[0].Title)
|
||||
@@ -147,7 +147,7 @@ func TestCreateBoardsAndBlocks(t *testing.T) {
|
||||
require.Equal(t, "private board", board2.Title)
|
||||
require.Equal(t, model.BoardTypePrivate, board2.Type)
|
||||
require.NotEqual(t, "board-id-2", board2.ID)
|
||||
blocks2, err := th.Server.App().GetBlocksForBoard(board2.ID)
|
||||
blocks2, err := th.Server.App().GetBlocks(model.QueryBlocksOptions{BoardID: board2.ID})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, blocks2, 1)
|
||||
require.Equal(t, "block 2", blocks2[0].Title)
|
||||
|
||||
@@ -62,7 +62,7 @@ func TestExportBoard(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, boardsImported, 1)
|
||||
boardImported := boardsImported[0]
|
||||
blocksImported, err := th.Server.App().GetBlocksForBoard(boardImported.ID)
|
||||
blocksImported, err := th.Server.App().GetBlocks(model.QueryBlocksOptions{BoardID: boardImported.ID})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, blocksImported, 1)
|
||||
require.Equal(t, block.Title, blocksImported[0].Title)
|
||||
|
||||
@@ -176,7 +176,7 @@ type QueryBlocksOptions struct {
|
||||
ParentID string // if not empty then filter for blocks belonging to specified parent
|
||||
BlockType BlockType // if not empty and not `TypeUnknown` then filter for records of specified block type
|
||||
Page int // page number to select when paginating
|
||||
PerPage int // number of blocks per page (default=-1, meaning unlimited)
|
||||
PerPage int // number of blocks per page (default=0, meaning unlimited)
|
||||
}
|
||||
|
||||
// QuerySubtreeOptions are query options that can be passed to GetSubTree methods.
|
||||
|
||||
@@ -536,66 +536,6 @@ func (mr *MockStoreMockRecorder) GetBlocksComplianceHistory(arg0 interface{}) *g
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBlocksComplianceHistory", reflect.TypeOf((*MockStore)(nil).GetBlocksComplianceHistory), arg0)
|
||||
}
|
||||
|
||||
// GetBlocksForBoard mocks base method.
|
||||
func (m *MockStore) GetBlocksForBoard(arg0 string) ([]*model0.Block, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetBlocksForBoard", arg0)
|
||||
ret0, _ := ret[0].([]*model0.Block)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetBlocksForBoard indicates an expected call of GetBlocksForBoard.
|
||||
func (mr *MockStoreMockRecorder) GetBlocksForBoard(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBlocksForBoard", reflect.TypeOf((*MockStore)(nil).GetBlocksForBoard), arg0)
|
||||
}
|
||||
|
||||
// GetBlocksWithParent mocks base method.
|
||||
func (m *MockStore) GetBlocksWithParent(arg0, arg1 string) ([]*model0.Block, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetBlocksWithParent", arg0, arg1)
|
||||
ret0, _ := ret[0].([]*model0.Block)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetBlocksWithParent indicates an expected call of GetBlocksWithParent.
|
||||
func (mr *MockStoreMockRecorder) GetBlocksWithParent(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBlocksWithParent", reflect.TypeOf((*MockStore)(nil).GetBlocksWithParent), arg0, arg1)
|
||||
}
|
||||
|
||||
// GetBlocksWithParentAndType mocks base method.
|
||||
func (m *MockStore) GetBlocksWithParentAndType(arg0, arg1, arg2 string) ([]*model0.Block, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetBlocksWithParentAndType", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].([]*model0.Block)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetBlocksWithParentAndType indicates an expected call of GetBlocksWithParentAndType.
|
||||
func (mr *MockStoreMockRecorder) GetBlocksWithParentAndType(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBlocksWithParentAndType", reflect.TypeOf((*MockStore)(nil).GetBlocksWithParentAndType), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// GetBlocksWithType mocks base method.
|
||||
func (m *MockStore) GetBlocksWithType(arg0, arg1 string) ([]*model0.Block, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetBlocksWithType", arg0, arg1)
|
||||
ret0, _ := ret[0].([]*model0.Block)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetBlocksWithType indicates an expected call of GetBlocksWithType.
|
||||
func (mr *MockStoreMockRecorder) GetBlocksWithType(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBlocksWithType", reflect.TypeOf((*MockStore)(nil).GetBlocksWithType), arg0, arg1)
|
||||
}
|
||||
|
||||
// GetBoard mocks base method.
|
||||
func (m *MockStore) GetBoard(arg0 string) (*model0.Board, error) {
|
||||
m.ctrl.T.Helper()
|
||||
|
||||
@@ -105,23 +105,6 @@ func (s *SQLStore) getBlocks(db sq.BaseRunner, opts model.QueryBlocksOptions) ([
|
||||
return s.blocksFromRows(rows)
|
||||
}
|
||||
|
||||
func (s *SQLStore) getBlocksWithParentAndType(db sq.BaseRunner, boardID, parentID string, blockType string) ([]*model.Block, error) {
|
||||
opts := model.QueryBlocksOptions{
|
||||
BoardID: boardID,
|
||||
ParentID: parentID,
|
||||
BlockType: model.BlockType(blockType),
|
||||
}
|
||||
return s.getBlocks(db, opts)
|
||||
}
|
||||
|
||||
func (s *SQLStore) getBlocksWithParent(db sq.BaseRunner, boardID, parentID string) ([]*model.Block, error) {
|
||||
opts := model.QueryBlocksOptions{
|
||||
BoardID: boardID,
|
||||
ParentID: parentID,
|
||||
}
|
||||
return s.getBlocks(db, opts)
|
||||
}
|
||||
|
||||
func (s *SQLStore) getBlocksByIDs(db sq.BaseRunner, ids []string) ([]*model.Block, error) {
|
||||
query := s.getQueryBuilder(db).
|
||||
Select(s.blockFields("")...).
|
||||
@@ -148,14 +131,6 @@ func (s *SQLStore) getBlocksByIDs(db sq.BaseRunner, ids []string) ([]*model.Bloc
|
||||
return blocks, nil
|
||||
}
|
||||
|
||||
func (s *SQLStore) getBlocksWithType(db sq.BaseRunner, boardID, blockType string) ([]*model.Block, error) {
|
||||
opts := model.QueryBlocksOptions{
|
||||
BoardID: boardID,
|
||||
BlockType: model.BlockType(blockType),
|
||||
}
|
||||
return s.getBlocks(db, opts)
|
||||
}
|
||||
|
||||
// getSubTree2 returns blocks within 2 levels of the given blockID.
|
||||
func (s *SQLStore) getSubTree2(db sq.BaseRunner, boardID string, blockID string, opts model.QuerySubtreeOptions) ([]*model.Block, error) {
|
||||
query := s.getQueryBuilder(db).
|
||||
@@ -188,13 +163,6 @@ func (s *SQLStore) getSubTree2(db sq.BaseRunner, boardID string, blockID string,
|
||||
return s.blocksFromRows(rows)
|
||||
}
|
||||
|
||||
func (s *SQLStore) getBlocksForBoard(db sq.BaseRunner, boardID string) ([]*model.Block, error) {
|
||||
opts := model.QueryBlocksOptions{
|
||||
BoardID: boardID,
|
||||
}
|
||||
return s.getBlocks(db, opts)
|
||||
}
|
||||
|
||||
func (s *SQLStore) blocksFromRows(rows *sql.Rows) ([]*model.Block, error) {
|
||||
results := []*model.Block{}
|
||||
|
||||
|
||||
@@ -166,7 +166,7 @@ func (s *SQLStore) duplicateBoard(db sq.BaseRunner, boardID string, userID strin
|
||||
}
|
||||
|
||||
bab.Boards = []*model.Board{board}
|
||||
blocks, err := s.getBlocksForBoard(db, boardID)
|
||||
blocks, err := s.getBlocks(db, model.QueryBlocksOptions{BoardID: boardID})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -326,26 +326,6 @@ func (s *SQLStore) GetBlocksComplianceHistory(opts model.QueryBlocksComplianceHi
|
||||
|
||||
}
|
||||
|
||||
func (s *SQLStore) GetBlocksForBoard(boardID string) ([]*model.Block, error) {
|
||||
return s.getBlocksForBoard(s.db, boardID)
|
||||
|
||||
}
|
||||
|
||||
func (s *SQLStore) GetBlocksWithParent(boardID string, parentID string) ([]*model.Block, error) {
|
||||
return s.getBlocksWithParent(s.db, boardID, parentID)
|
||||
|
||||
}
|
||||
|
||||
func (s *SQLStore) GetBlocksWithParentAndType(boardID string, parentID string, blockType string) ([]*model.Block, error) {
|
||||
return s.getBlocksWithParentAndType(s.db, boardID, parentID, blockType)
|
||||
|
||||
}
|
||||
|
||||
func (s *SQLStore) GetBlocksWithType(boardID string, blockType string) ([]*model.Block, error) {
|
||||
return s.getBlocksWithType(s.db, boardID, blockType)
|
||||
|
||||
}
|
||||
|
||||
func (s *SQLStore) GetBoard(id string) (*model.Board, error) {
|
||||
return s.getBoard(s.db, id)
|
||||
|
||||
|
||||
@@ -18,12 +18,8 @@ const CardLimitTimestampSystemKey = "card_limit_timestamp"
|
||||
// Store represents the abstraction of the data storage.
|
||||
type Store interface {
|
||||
GetBlocks(opts model.QueryBlocksOptions) ([]*model.Block, error)
|
||||
GetBlocksWithParentAndType(boardID, parentID string, blockType string) ([]*model.Block, error)
|
||||
GetBlocksWithParent(boardID, parentID string) ([]*model.Block, error)
|
||||
GetBlocksByIDs(ids []string) ([]*model.Block, error)
|
||||
GetBlocksWithType(boardID, blockType string) ([]*model.Block, error)
|
||||
GetSubTree2(boardID, blockID string, opts model.QuerySubtreeOptions) ([]*model.Block, error)
|
||||
GetBlocksForBoard(boardID string) ([]*model.Block, error)
|
||||
// @withTransaction
|
||||
InsertBlock(block *model.Block, userID string) error
|
||||
// @withTransaction
|
||||
|
||||
@@ -69,7 +69,7 @@ func testInsertBlock(t *testing.T, store store.Store) {
|
||||
userID := testUserID
|
||||
boardID := testBoardID
|
||||
|
||||
blocks, errBlocks := store.GetBlocksForBoard(boardID)
|
||||
blocks, errBlocks := store.GetBlocks(model.QueryBlocksOptions{BoardID: boardID})
|
||||
require.NoError(t, errBlocks)
|
||||
initialCount := len(blocks)
|
||||
|
||||
@@ -85,7 +85,7 @@ func testInsertBlock(t *testing.T, store store.Store) {
|
||||
err := store.InsertBlock(block, "user-id-1")
|
||||
require.NoError(t, err)
|
||||
|
||||
blocks, err := store.GetBlocksForBoard(boardID)
|
||||
blocks, err := store.GetBlocks(model.QueryBlocksOptions{BoardID: boardID})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, blocks, initialCount+1)
|
||||
|
||||
@@ -105,7 +105,7 @@ func testInsertBlock(t *testing.T, store store.Store) {
|
||||
err := store.InsertBlock(block, "user-id-1")
|
||||
require.Error(t, err)
|
||||
|
||||
blocks, err := store.GetBlocksForBoard(boardID)
|
||||
blocks, err := store.GetBlocks(model.QueryBlocksOptions{BoardID: boardID})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, blocks, initialCount+1)
|
||||
})
|
||||
@@ -121,7 +121,7 @@ func testInsertBlock(t *testing.T, store store.Store) {
|
||||
err := store.InsertBlock(block, "user-id-1")
|
||||
require.Error(t, err)
|
||||
|
||||
blocks, err := store.GetBlocksForBoard(boardID)
|
||||
blocks, err := store.GetBlocks(model.QueryBlocksOptions{BoardID: boardID})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, blocks, initialCount+1)
|
||||
})
|
||||
@@ -204,7 +204,7 @@ func testInsertBlock(t *testing.T, store store.Store) {
|
||||
func testInsertBlocks(t *testing.T, store store.Store) {
|
||||
userID := testUserID
|
||||
|
||||
blocks, errBlocks := store.GetBlocksForBoard("id-test")
|
||||
blocks, errBlocks := store.GetBlocks(model.QueryBlocksOptions{BoardID: "id-test"})
|
||||
require.NoError(t, errBlocks)
|
||||
initialCount := len(blocks)
|
||||
|
||||
@@ -227,7 +227,7 @@ func testInsertBlocks(t *testing.T, store store.Store) {
|
||||
err := store.InsertBlocks(newBlocks, "user-id-1")
|
||||
require.Error(t, err)
|
||||
|
||||
blocks, err := store.GetBlocksForBoard("id-test")
|
||||
blocks, err := store.GetBlocks(model.QueryBlocksOptions{BoardID: "id-test"})
|
||||
require.NoError(t, err)
|
||||
// no blocks should have been inserted
|
||||
require.Len(t, blocks, initialCount)
|
||||
@@ -249,7 +249,7 @@ func testPatchBlock(t *testing.T, store store.Store) {
|
||||
err := store.InsertBlock(block, "user-id-1")
|
||||
require.NoError(t, err)
|
||||
|
||||
blocks, errBlocks := store.GetBlocksForBoard(boardID)
|
||||
blocks, errBlocks := store.GetBlocks(model.QueryBlocksOptions{BoardID: boardID})
|
||||
require.NoError(t, errBlocks)
|
||||
initialCount := len(blocks)
|
||||
|
||||
@@ -259,7 +259,7 @@ func testPatchBlock(t *testing.T, store store.Store) {
|
||||
require.ErrorAs(t, err, &nf)
|
||||
require.True(t, model.IsErrNotFound(err))
|
||||
|
||||
blocks, err := store.GetBlocksForBoard(boardID)
|
||||
blocks, err := store.GetBlocks(model.QueryBlocksOptions{BoardID: boardID})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, blocks, initialCount)
|
||||
})
|
||||
@@ -272,7 +272,7 @@ func testPatchBlock(t *testing.T, store store.Store) {
|
||||
err := store.PatchBlock("id-test", blockPatch, "user-id-1")
|
||||
require.Error(t, err)
|
||||
|
||||
blocks, err := store.GetBlocksForBoard(boardID)
|
||||
blocks, err := store.GetBlocks(model.QueryBlocksOptions{BoardID: boardID})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, blocks, initialCount)
|
||||
})
|
||||
@@ -452,7 +452,7 @@ var (
|
||||
|
||||
func testGetSubTree2(t *testing.T, store store.Store) {
|
||||
boardID := testBoardID
|
||||
blocks, err := store.GetBlocksForBoard(boardID)
|
||||
blocks, err := store.GetBlocks(model.QueryBlocksOptions{BoardID: boardID})
|
||||
require.NoError(t, err)
|
||||
initialCount := len(blocks)
|
||||
|
||||
@@ -460,7 +460,7 @@ func testGetSubTree2(t *testing.T, store store.Store) {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
defer DeleteBlocks(t, store, subtreeSampleBlocks, "test")
|
||||
|
||||
blocks, err = store.GetBlocksForBoard(boardID)
|
||||
blocks, err = store.GetBlocks(model.QueryBlocksOptions{BoardID: boardID})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, blocks, initialCount+6)
|
||||
|
||||
@@ -492,7 +492,7 @@ func testDeleteBlock(t *testing.T, store store.Store) {
|
||||
userID := testUserID
|
||||
boardID := testBoardID
|
||||
|
||||
blocks, err := store.GetBlocksForBoard(boardID)
|
||||
blocks, err := store.GetBlocks(model.QueryBlocksOptions{BoardID: boardID})
|
||||
require.NoError(t, err)
|
||||
initialCount := len(blocks)
|
||||
|
||||
@@ -516,7 +516,7 @@ func testDeleteBlock(t *testing.T, store store.Store) {
|
||||
InsertBlocks(t, store, blocksToInsert, "user-id-1")
|
||||
defer DeleteBlocks(t, store, blocksToInsert, "test")
|
||||
|
||||
blocks, err = store.GetBlocksForBoard(boardID)
|
||||
blocks, err = store.GetBlocks(model.QueryBlocksOptions{BoardID: boardID})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, blocks, initialCount+3)
|
||||
|
||||
@@ -550,7 +550,7 @@ func testUndeleteBlock(t *testing.T, store store.Store) {
|
||||
boardID := testBoardID
|
||||
userID := testUserID
|
||||
|
||||
blocks, err := store.GetBlocksForBoard(boardID)
|
||||
blocks, err := store.GetBlocks(model.QueryBlocksOptions{BoardID: boardID})
|
||||
require.NoError(t, err)
|
||||
initialCount := len(blocks)
|
||||
|
||||
@@ -574,7 +574,7 @@ func testUndeleteBlock(t *testing.T, store store.Store) {
|
||||
InsertBlocks(t, store, blocksToInsert, "user-id-1")
|
||||
defer DeleteBlocks(t, store, blocksToInsert, "test")
|
||||
|
||||
blocks, err = store.GetBlocksForBoard(boardID)
|
||||
blocks, err = store.GetBlocks(model.QueryBlocksOptions{BoardID: boardID})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, blocks, initialCount+3)
|
||||
|
||||
@@ -643,7 +643,7 @@ func testUndeleteBlock(t *testing.T, store store.Store) {
|
||||
|
||||
func testGetBlocks(t *testing.T, store store.Store) {
|
||||
boardID := testBoardID
|
||||
blocks, err := store.GetBlocksForBoard(boardID)
|
||||
blocks, err := store.GetBlocks(model.QueryBlocksOptions{BoardID: boardID})
|
||||
require.NoError(t, err)
|
||||
|
||||
blocksToInsert := []*model.Block{
|
||||
@@ -686,65 +686,74 @@ func testGetBlocks(t *testing.T, store store.Store) {
|
||||
InsertBlocks(t, store, blocksToInsert, "user-id-1")
|
||||
defer DeleteBlocks(t, store, blocksToInsert, "test")
|
||||
|
||||
t.Run("not existing parent", func(t *testing.T) {
|
||||
t.Run("not existing parent with type", func(t *testing.T) {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
blocks, err = store.GetBlocksWithParentAndType(boardID, "not-exists", "test")
|
||||
opts := model.QueryBlocksOptions{BoardID: boardID, ParentID: "not-exists", BlockType: model.BlockType("test")}
|
||||
blocks, err = store.GetBlocks(opts)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, blocks)
|
||||
})
|
||||
|
||||
t.Run("not existing type", func(t *testing.T) {
|
||||
t.Run("not existing type with parent", func(t *testing.T) {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
blocks, err = store.GetBlocksWithParentAndType(boardID, "block1", "not-existing")
|
||||
opts := model.QueryBlocksOptions{BoardID: boardID, ParentID: "block1", BlockType: model.BlockType("not-existing")}
|
||||
blocks, err = store.GetBlocks(opts)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, blocks)
|
||||
})
|
||||
|
||||
t.Run("valid parent and type", func(t *testing.T) {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
blocks, err = store.GetBlocksWithParentAndType(boardID, "block1", "test")
|
||||
opts := model.QueryBlocksOptions{BoardID: boardID, ParentID: "block1", BlockType: model.BlockType("test")}
|
||||
blocks, err = store.GetBlocks(opts)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, blocks, 2)
|
||||
})
|
||||
|
||||
t.Run("not existing parent", func(t *testing.T) {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
blocks, err = store.GetBlocksWithParent(boardID, "not-exists")
|
||||
opts := model.QueryBlocksOptions{BoardID: boardID, ParentID: "not-exists"}
|
||||
blocks, err = store.GetBlocks(opts)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, blocks)
|
||||
})
|
||||
|
||||
t.Run("valid parent", func(t *testing.T) {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
blocks, err = store.GetBlocksWithParent(boardID, "block1")
|
||||
opts := model.QueryBlocksOptions{BoardID: boardID, ParentID: "block1"}
|
||||
blocks, err = store.GetBlocks(opts)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, blocks, 3)
|
||||
})
|
||||
|
||||
t.Run("not existing type", func(t *testing.T) {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
blocks, err = store.GetBlocksWithType(boardID, "not-exists")
|
||||
opts := model.QueryBlocksOptions{BoardID: boardID, BlockType: model.BlockType("not-exists")}
|
||||
blocks, err = store.GetBlocks(opts)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, blocks)
|
||||
})
|
||||
|
||||
t.Run("valid type", func(t *testing.T) {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
blocks, err = store.GetBlocksWithType(boardID, "test")
|
||||
opts := model.QueryBlocksOptions{BoardID: boardID, BlockType: model.BlockType("test")}
|
||||
blocks, err = store.GetBlocks(opts)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, blocks, 4)
|
||||
})
|
||||
|
||||
t.Run("not existing board", func(t *testing.T) {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
blocks, err = store.GetBlocksForBoard("not-exists")
|
||||
opts := model.QueryBlocksOptions{BoardID: "not-exists"}
|
||||
blocks, err = store.GetBlocks(opts)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, blocks)
|
||||
})
|
||||
|
||||
t.Run("all blocks of the a board", func(t *testing.T) {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
blocks, err = store.GetBlocksForBoard(boardID)
|
||||
opts := model.QueryBlocksOptions{BoardID: boardID}
|
||||
blocks, err = store.GetBlocks(opts)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, blocks, 5)
|
||||
})
|
||||
@@ -863,7 +872,7 @@ func testDuplicateBlock(t *testing.T, store store.Store) {
|
||||
|
||||
func testGetBlockMetadata(t *testing.T, store store.Store) {
|
||||
boardID := testBoardID
|
||||
blocks, err := store.GetBlocksForBoard(boardID)
|
||||
blocks, err := store.GetBlocks(model.QueryBlocksOptions{BoardID: boardID})
|
||||
require.NoError(t, err)
|
||||
|
||||
blocksToInsert := []*model.Block{
|
||||
@@ -1082,12 +1091,20 @@ func testUndeleteBlockChildren(t *testing.T, store store.Store) {
|
||||
require.Nil(t, block)
|
||||
|
||||
// ensure the card children were deleted
|
||||
blocks, err := store.GetBlocksWithParentAndType(cardDelete.BoardID, cardDelete.ID, model.TypeText)
|
||||
blocks, err := store.GetBlocks(model.QueryBlocksOptions{
|
||||
BoardID: cardDelete.BoardID,
|
||||
ParentID: cardDelete.ID,
|
||||
BlockType: model.TypeText},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, blocks)
|
||||
|
||||
// ensure the other card children remain.
|
||||
blocks, err = store.GetBlocksWithParentAndType(cardKeep.BoardID, cardKeep.ID, model.TypeText)
|
||||
blocks, err = store.GetBlocks(model.QueryBlocksOptions{
|
||||
BoardID: cardKeep.BoardID,
|
||||
ParentID: cardKeep.ID,
|
||||
BlockType: model.TypeText},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, blocks, len(blocksKeep))
|
||||
|
||||
@@ -1101,7 +1118,11 @@ func testUndeleteBlockChildren(t *testing.T, store store.Store) {
|
||||
require.NotNil(t, block)
|
||||
|
||||
// ensure the card children were restored
|
||||
blocks, err = store.GetBlocksWithParentAndType(cardDelete.BoardID, cardDelete.ID, model.TypeText)
|
||||
blocks, err = store.GetBlocks(model.QueryBlocksOptions{
|
||||
BoardID: cardDelete.BoardID,
|
||||
ParentID: cardDelete.ID,
|
||||
BlockType: model.TypeText},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, blocks, len(blocksDelete))
|
||||
})
|
||||
@@ -1117,12 +1138,12 @@ func testUndeleteBlockChildren(t *testing.T, store store.Store) {
|
||||
require.Nil(t, board)
|
||||
|
||||
// ensure all cards and blocks for the board were deleted
|
||||
blocks, err := store.GetBlocksForBoard(boardDelete.ID)
|
||||
blocks, err := store.GetBlocks(model.QueryBlocksOptions{BoardID: boardDelete.ID})
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, blocks)
|
||||
|
||||
// ensure the other board's cards and blocks remain.
|
||||
blocks, err = store.GetBlocksForBoard(boardKeep.ID)
|
||||
blocks, err = store.GetBlocks(model.QueryBlocksOptions{BoardID: boardKeep.ID})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, blocks, len(blocksKeep)+len(cardsKeep))
|
||||
|
||||
@@ -1136,7 +1157,7 @@ func testUndeleteBlockChildren(t *testing.T, store store.Store) {
|
||||
require.NotNil(t, board)
|
||||
|
||||
// ensure the board's cards and blocks were restored.
|
||||
blocks, err = store.GetBlocksForBoard(boardDelete.ID)
|
||||
blocks, err = store.GetBlocks(model.QueryBlocksOptions{BoardID: boardDelete.ID})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, blocks, len(blocksDelete)+len(cardsDelete))
|
||||
})
|
||||
|
||||
@@ -98,7 +98,7 @@ func LoadData(t *testing.T, store store.Store) {
|
||||
func testRunDataRetention(t *testing.T, store store.Store, batchSize int) {
|
||||
LoadData(t, store)
|
||||
|
||||
blocks, err := store.GetBlocksForBoard(boardID)
|
||||
blocks, err := store.GetBlocks(model.QueryBlocksOptions{BoardID: boardID})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, blocks, 4)
|
||||
initialCount := len(blocks)
|
||||
@@ -115,7 +115,7 @@ func testRunDataRetention(t *testing.T, store store.Store, batchSize int) {
|
||||
require.True(t, deletions > int64(initialCount))
|
||||
|
||||
// expect all blocks to be deleted.
|
||||
blocks, errBlocks := store.GetBlocksForBoard(boardID)
|
||||
blocks, errBlocks := store.GetBlocks(model.QueryBlocksOptions{BoardID: boardID})
|
||||
require.NoError(t, errBlocks)
|
||||
require.Equal(t, 0, len(blocks))
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user