mirror of https://github.com/harness/drone.git
fix: [CDE-202]:udpate query for bulk update git instance state (#2777)
* add update all * udpate query for bulk update git instance statepull/3571/head
parent
8b53e5b92a
commit
f1cb9986c2
|
@ -20,6 +20,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/harness/gitness/types"
|
||||
"github.com/harness/gitness/types/enum"
|
||||
)
|
||||
|
||||
func (c *Service) UpdateInstance(
|
||||
|
@ -33,3 +34,16 @@ func (c *Service) UpdateInstance(
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Service) UpdateAllStateInstance(
|
||||
ctx context.Context,
|
||||
status enum.GitspaceInstanceStateType,
|
||||
instancesIDs []int64,
|
||||
) error {
|
||||
updatedUnixTime := time.Now().UnixMilli()
|
||||
err := c.gitspaceInstanceStore.BulkUpdateState(ctx, status, updatedUnixTime, instancesIDs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to update all statue of gitspace instances: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -677,7 +677,12 @@ type (
|
|||
Update(ctx context.Context, gitspaceInstance *types.GitspaceInstance) error
|
||||
|
||||
// BulkUpdateState updates state of given gitspace instance IDs to given state
|
||||
BulkUpdateState(ctx context.Context, state enum.GitspaceInstanceStateType, gitspaceInstanceIDs []int64) error
|
||||
BulkUpdateState(
|
||||
ctx context.Context,
|
||||
state enum.GitspaceInstanceStateType,
|
||||
updateTimeUnix int64,
|
||||
gitspaceInstanceIDs []int64,
|
||||
) error
|
||||
|
||||
// List lists the gitspace instance present in a parent space ID in the datastore.
|
||||
List(ctx context.Context, filter *types.GitspaceFilter) ([]*types.GitspaceInstance, error)
|
||||
|
|
|
@ -259,11 +259,13 @@ func (g gitspaceInstanceStore) Update(
|
|||
func (g gitspaceInstanceStore) BulkUpdateState(
|
||||
ctx context.Context,
|
||||
state enum.GitspaceInstanceStateType,
|
||||
updateTimeUnix int64,
|
||||
gitspaceInstanceIDs []int64,
|
||||
) error {
|
||||
stmt := database.Builder.
|
||||
Update(gitspaceInstanceTable).
|
||||
Set("gits_state", state).
|
||||
Set("gits_updated", updateTimeUnix).
|
||||
Where(squirrel.Eq{"gits_id": gitspaceInstanceIDs})
|
||||
|
||||
sqlStr, args, err := stmt.ToSql()
|
||||
|
|
Loading…
Reference in New Issue