Skip to content

Commit

Permalink
ADD raw sql for set action public or private storage method.
Browse files Browse the repository at this point in the history
ADD raw sql for set action public or private storage method.
  • Loading branch information
karminski committed Feb 6, 2024
1 parent 054cdde commit 7cb9cc2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 29 deletions.
8 changes: 4 additions & 4 deletions src/controller/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ func (controller *Controller) ReleaseApp(c *gin.Context) {
return
}
performanceTimerEnd0_2 := time.Now().UnixMilli()
fmt.Printf("[timer] phrase 0_2: %d ms\n", -(performanceTimerStart - performanceTimerEnd0_2))
fmt.Printf("[timer] phrase 0_2: %d ms\n", -(performanceTimerEnd0_1 - performanceTimerEnd0_2))

// fetch app
app, errInRetrieveApp := controller.Storage.AppStorage.RetrieveAppByTeamIDAndAppID(teamID, appID)
Expand All @@ -796,7 +796,7 @@ func (controller *Controller) ReleaseApp(c *gin.Context) {
}

performanceTimerEnd0_3 := time.Now().UnixMilli()
fmt.Printf("[timer] phrase 0_3: %d ms\n", -(performanceTimerStart - performanceTimerEnd0_3))
fmt.Printf("[timer] phrase 0_3: %d ms\n", -(performanceTimerEnd0_2 - performanceTimerEnd0_3))

// check team can release public app, the free team can not release app as public.
// but when publish app to marketplace, the can re-deploy this app as public.
Expand All @@ -818,7 +818,7 @@ func (controller *Controller) ReleaseApp(c *gin.Context) {
}
}
performanceTimerEnd0_4 := time.Now().UnixMilli()
fmt.Printf("[timer] phrase 0_4: %d ms\n", -(performanceTimerStart - performanceTimerEnd0_4))
fmt.Printf("[timer] phrase 0_4: %d ms\n", -(performanceTimerEnd0_3 - performanceTimerEnd0_4))

// config app & action public status
if req.ExportPublic() {
Expand All @@ -837,7 +837,7 @@ func (controller *Controller) ReleaseApp(c *gin.Context) {
}

performanceTimerEnd0_5 := time.Now().UnixMilli()
fmt.Printf("[timer] phrase 0_5: %d ms\n", -(performanceTimerStart - performanceTimerEnd0_5))
fmt.Printf("[timer] phrase 0_5: %d ms\n", -(performanceTimerEnd0_4 - performanceTimerEnd0_5))

// release app version
treeStateLatestVersion, _ := controller.Storage.TreeStateStorage.RetrieveTreeStatesLatestVersion(teamID, appID)
Expand Down
34 changes: 9 additions & 25 deletions src/storage/action_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
"gorm.io/gorm"
)

const SQL_SET_ACTION_PUBLIC = `update actions set config = jsonb_set(config, '{public}', 'true'::jsonb, true), updated_by= ? where team_id = ? and app_ref_id = ?;`
const SQL_SET_ACTION_PRIVATE = `update actions set config = jsonb_set(config, '{public}', 'false'::jsonb, true), updated_by= ? where team_id = ? and app_ref_id = ?;`

type ActionStorage struct {
logger *zap.SugaredLogger
db *gorm.DB
Expand Down Expand Up @@ -74,36 +77,17 @@ func (impl *ActionStorage) UpdatePrivacyByTeamIDAndAppIDAndUserID(teamID int, ap
}

func (impl *ActionStorage) MakeActionPublicByTeamIDAndAppID(teamID int, appID int, userID int) error {
actions, errInGetAll := impl.RetrieveAll(teamID, appID)
if errInGetAll != nil {
return errInGetAll
}
// set status
for _, action := range actions {
action.SetPublic(userID)
// update
errorInUpdate := impl.UpdateWholeAction(action)
if errorInUpdate != nil {
return errorInUpdate
}

tx := impl.db.Exec(SQL_SET_ACTION_PUBLIC, userID, teamID, appID)
if tx.Error != nil {
return tx.Error
}
return nil
}

func (impl *ActionStorage) MakeActionPrivateByTeamIDAndAppID(teamID int, appID int, userID int) error {
actions, errInGetAll := impl.RetrieveAll(teamID, appID)
if errInGetAll != nil {
return errInGetAll
}
// set status
for _, action := range actions {
action.SetPrivate(userID)
// update
errorInUpdate := impl.UpdateWholeAction(action)
if errorInUpdate != nil {
return errorInUpdate
}
tx := impl.db.Exec(SQL_SET_ACTION_PRIVATE, userID, teamID, appID)
if tx.Error != nil {
return tx.Error
}
return nil
}
Expand Down

0 comments on commit 7cb9cc2

Please sign in to comment.