appview/models: fix logic issue when converting label record -> label ops #604

merged
opened by oppi.li targeting master from push-plpuqtyrprou

the ordering of ops should be deletes first followed by additions, in order for ingestions to be idempotent. after every optimistic update the the DB, we ingest the same record via the firehose. an ordering difference resulted in certain additions being marked as no-ops when in reality, it should be an addition followed by a deletion.

Signed-off-by: oppiliappan me@oppi.li

Changed files
+5 -4
appview
models
+5 -4
appview/models/label.go
··· 232 } 233 234 var ops []LabelOp 235 - for _, o := range record.Add { 236 if o != nil { 237 op := mkOp(o) 238 - op.Operation = LabelOperationAdd 239 ops = append(ops, op) 240 } 241 } 242 - for _, o := range record.Delete { 243 if o != nil { 244 op := mkOp(o) 245 - op.Operation = LabelOperationDel 246 ops = append(ops, op) 247 } 248 }
··· 232 } 233 234 var ops []LabelOp 235 + // deletes first, then additions 236 + for _, o := range record.Delete { 237 if o != nil { 238 op := mkOp(o) 239 + op.Operation = LabelOperationDel 240 ops = append(ops, op) 241 } 242 } 243 + for _, o := range record.Add { 244 if o != nil { 245 op := mkOp(o) 246 + op.Operation = LabelOperationAdd 247 ops = append(ops, op) 248 } 249 }