func updatePlacements(view db.Database, spec stitch.Stitch) { var placements db.PlacementSlice for _, sp := range spec.Placements { placements = append(placements, db.Placement{ TargetLabel: sp.TargetLabel, Exclusive: sp.Exclusive, OtherLabel: sp.OtherLabel, Provider: sp.Provider, Size: sp.Size, Region: sp.Region, }) } key := func(val interface{}) interface{} { p := val.(db.Placement) p.ID = 0 return p } dbPlacements := db.PlacementSlice(view.SelectFromPlacement(nil)) _, addSet, removeSet := join.HashJoin(placements, dbPlacements, key, key) for _, toAddIntf := range addSet { toAdd := toAddIntf.(db.Placement) id := view.InsertPlacement().ID toAdd.ID = id view.Commit(toAdd) } for _, toRemove := range removeSet { view.Remove(toRemove.(db.Placement)) } }
func updatePlacements(view db.Database, spec stitch.Stitch) { stitchPlacements := toDBPlacements(spec.QueryPlacements()) key := func(val interface{}) interface{} { pVal := val.(db.Placement) return struct { tl string rule db.PlacementRule }{pVal.TargetLabel, pVal.Rule} } _, addSet, removeSet := join.HashJoin(stitchPlacements, db.PlacementSlice(view.SelectFromPlacement(nil)), key, key) for _, toAddIntf := range addSet { toAdd := toAddIntf.(db.Placement) newPlacement := view.InsertPlacement() newPlacement.TargetLabel = toAdd.TargetLabel newPlacement.Rule = toAdd.Rule view.Commit(newPlacement) } for _, toRemove := range removeSet { view.Remove(toRemove.(db.Placement)) } }