treewide: 改进opslog记录update diff

action为ACT_UPDATE,仅当len(UpdateDiffs) > 0时才记录
This commit is contained in:
Yousong Zhou
2019-03-13 14:20:54 +00:00
parent 223c9f6461
commit 098d62bdc5
11 changed files with 100 additions and 47 deletions
+1 -3
View File
@@ -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
}
+2 -10
View File
@@ -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)
+9
View File
@@ -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()