in datasource/etcd/schema.go [324:382]
func transformSchemaIDsAndOptions(ctx context.Context, domainProject string, serviceID string,
oldSchemaIDs []string, contentRequest *schema.PutManyContentRequest) ([]string, []etcdadpt.OpOptions) {
pendingDeleteSchemaIDs := mapset.NewSet()
for _, schemaID := range oldSchemaIDs {
pendingDeleteSchemaIDs.Add(schemaID)
}
var options []etcdadpt.OpOptions
schemaIDs := make([]string, 0, len(contentRequest.Contents))
for i, content := range contentRequest.Contents {
schemaID := contentRequest.SchemaIDs[i]
refKey := path.GenerateServiceSchemaRefKey(domainProject, serviceID, schemaID)
contentKey := path.GenerateServiceSchemaContentKey(domainProject, content.Hash)
summaryKey := path.GenerateServiceSchemaSummaryKey(domainProject, serviceID, schemaID)
options = append(options,
etcdadpt.OpPut(etcdadpt.WithStrKey(refKey), etcdadpt.WithStrValue(content.Hash)),
etcdadpt.OpPut(etcdadpt.WithStrKey(contentKey), etcdadpt.WithStrValue(content.Content)),
etcdadpt.OpPut(etcdadpt.WithStrKey(summaryKey), etcdadpt.WithStrValue(content.Summary)),
)
refOpts, err := sync.GenUpdateOpts(ctx, datasource.ResourceKV, content.Hash, sync.WithOpts(map[string]string{"key": refKey}))
if err != nil {
log.Error("fail to create update opts", err)
}
options = append(options, refOpts...)
contentOpts, err := sync.GenUpdateOpts(ctx, datasource.ResourceKV, content.Content, sync.WithOpts(map[string]string{"key": contentKey}))
if err != nil {
log.Error("fail to create update opts", err)
}
options = append(options, contentOpts...)
summaryOpts, err := sync.GenUpdateOpts(ctx, datasource.ResourceKV, content.Summary, sync.WithOpts(map[string]string{"key": summaryKey}))
if err != nil {
log.Error("fail to create update opts", err)
}
options = append(options, summaryOpts...)
schemaIDs = append(schemaIDs, schemaID)
pendingDeleteSchemaIDs.Remove(schemaID)
}
for item := range pendingDeleteSchemaIDs.Iter() {
schemaID := item.(string)
refKey := path.GenerateServiceSchemaRefKey(domainProject, serviceID, schemaID)
summaryKey := path.GenerateServiceSchemaSummaryKey(domainProject, serviceID, schemaID)
options = append(options,
etcdadpt.OpDel(etcdadpt.WithStrKey(refKey)),
etcdadpt.OpDel(etcdadpt.WithStrKey(summaryKey)),
)
refOpts, err := sync.GenDeleteOpts(ctx, datasource.ResourceKV, refKey, refKey)
if err != nil {
log.Error("fail to create update opts", err)
}
options = append(options, refOpts...)
summaryOpt, err := sync.GenDeleteOpts(ctx, datasource.ResourceKV, summaryKey, summaryKey)
if err != nil {
log.Error("fail to create update opts", err)
}
options = append(options, summaryOpt...)
}
return schemaIDs, options
}