1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-11-27 08:31:20 +02:00

Update board store to return inserted / patched values without querying the DB after modifying them (#3832)

* Update board store to return inserted / patched values without querying the DB after modifying them

* Remove redundant condition check after error refactoring
This commit is contained in:
Miguel de la Cruz 2022-09-13 12:43:03 +02:00 committed by GitHub
parent 08c0b7a2fd
commit f35ac66232
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -340,13 +340,15 @@ func (s *SQLStore) insertBoard(db sq.BaseRunner, board *model.Board, userID stri
Columns(boardFields("")...)
now := utils.GetMillis()
board.ModifiedBy = userID
board.UpdateAt = now
insertQueryValues := map[string]interface{}{
"id": board.ID,
"team_id": board.TeamID,
"channel_id": board.ChannelID,
"created_by": board.CreatedBy,
"modified_by": userID,
"modified_by": board.ModifiedBy,
"type": board.Type,
"title": board.Title,
"minimum_role": board.MinimumRole,
@ -358,14 +360,14 @@ func (s *SQLStore) insertBoard(db sq.BaseRunner, board *model.Board, userID stri
"properties": propertiesBytes,
"card_properties": cardPropertiesBytes,
"create_at": board.CreateAt,
"update_at": now,
"update_at": board.UpdateAt,
"delete_at": board.DeleteAt,
}
if existingBoard != nil {
query := s.getQueryBuilder(db).Update(s.tablePrefix+"boards").
Where(sq.Eq{"id": board.ID}).
Set("modified_by", userID).
Set("modified_by", board.ModifiedBy).
Set("type", board.Type).
Set("channel_id", board.ChannelID).
Set("minimum_role", board.MinimumRole).
@ -377,7 +379,7 @@ func (s *SQLStore) insertBoard(db sq.BaseRunner, board *model.Board, userID stri
Set("template_version", board.TemplateVersion).
Set("properties", propertiesBytes).
Set("card_properties", cardPropertiesBytes).
Set("update_at", now).
Set("update_at", board.UpdateAt).
Set("delete_at", board.DeleteAt)
if _, err := query.Exec(); err != nil {
@ -385,9 +387,10 @@ func (s *SQLStore) insertBoard(db sq.BaseRunner, board *model.Board, userID stri
return nil, fmt.Errorf("insertBoard error occurred while updating existing board %s: %w", board.ID, err)
}
} else {
insertQueryValues["created_by"] = userID
insertQueryValues["create_at"] = now
insertQueryValues["update_at"] = now
board.CreatedBy = userID
board.CreateAt = now
insertQueryValues["created_by"] = board.CreatedBy
insertQueryValues["create_at"] = board.CreateAt
query := insertQuery.SetMap(insertQueryValues).Into(s.tablePrefix + "boards")
if _, err := query.Exec(); err != nil {
@ -402,7 +405,7 @@ func (s *SQLStore) insertBoard(db sq.BaseRunner, board *model.Board, userID stri
return nil, fmt.Errorf("failed to insert board %s history: %w", board.ID, err)
}
return s.getBoard(db, board.ID)
return board, nil
}
func (s *SQLStore) patchBoard(db sq.BaseRunner, boardID string, boardPatch *model.BoardPatch, userID string) (*model.Board, error) {
@ -410,9 +413,6 @@ func (s *SQLStore) patchBoard(db sq.BaseRunner, boardID string, boardPatch *mode
if err != nil {
return nil, err
}
if existingBoard == nil {
return nil, model.NewErrNotFound("board ID=" + boardID)
}
board := boardPatch.Patch(existingBoard)
return s.insertBoard(db, board, userID)