Remove redundant store APIs for Boards: (#22968)

- getBlocksWithParent
- getBlocksWithParentAndType
- getBlocksWithType
- getBlocksForBoard
Этот коммит содержится в:
Doug Lauder
2023-04-17 06:33:07 -04:00
коммит произвёл GitHub
родитель 496b1e4e1c
Коммит a80e1e21b9
14 изменённых файлов: 128 добавлений и 190 удалений

Просмотреть файл

@@ -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
}