mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-25 10:16:12 +08:00
treewide: 改进opslog记录update diff
action为ACT_UPDATE,仅当len(UpdateDiffs) > 0时才记录
This commit is contained in:
@@ -132,8 +132,6 @@ func (model *SAdminSharableVirtualResourceBase) setInfo(
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if diff != nil {
|
||||
OpsLog.LogEvent(model, ACT_UPDATE, diff, userCred)
|
||||
}
|
||||
OpsLog.LogEvent(model, ACT_UPDATE, diff, userCred)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1259,16 +1259,8 @@ func updateItem(manager IModelManager, item IModel, ctx context.Context, userCre
|
||||
log.Errorf("save update error: %s", err)
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
if diff != nil {
|
||||
diffStr := sqlchemy.UpdateDiffString(diff)
|
||||
if len(diffStr) > 0 {
|
||||
item.PostUpdate(ctx, userCred, query, dataDict)
|
||||
OpsLog.LogEvent(item, ACT_UPDATE, diffStr, userCred)
|
||||
logclient.AddActionLogWithContext(ctx, item, logclient.ACT_UPDATE, diffStr, userCred, true)
|
||||
}
|
||||
} else {
|
||||
logclient.AddActionLogWithContext(ctx, item, logclient.ACT_UPDATE, "", userCred, true)
|
||||
}
|
||||
OpsLog.LogEvent(item, ACT_UPDATE, diff, userCred)
|
||||
logclient.AddActionLogWithContext(ctx, item, logclient.ACT_UPDATE, diff, userCred, true)
|
||||
|
||||
item.PostUpdate(ctx, userCred, query, data)
|
||||
|
||||
|
||||
@@ -230,6 +230,15 @@ func (manager *SOpsLogManager) LogEvent(model IModel, action string, notes inter
|
||||
if len(model.GetId()) == 0 || len(model.GetName()) == 0 {
|
||||
return
|
||||
}
|
||||
if action == ACT_UPDATE {
|
||||
// skip empty diff
|
||||
if notes == nil {
|
||||
return
|
||||
}
|
||||
if uds, ok := notes.(sqlchemy.UpdateDiffs); ok && len(uds) == 0 {
|
||||
return
|
||||
}
|
||||
}
|
||||
opslog := SOpsLog{}
|
||||
opslog.ObjType = model.Keyword()
|
||||
opslog.ObjId = model.GetId()
|
||||
|
||||
Reference in New Issue
Block a user