// AchieveDesiredState turns the application state into a given `desired` state with the smallest
// number of Put/Delete calls.
AchieveDesiredState turns the application state into a given `desired` state with the smallest
number of Put/Delete calls.
// AchieveDesiredState turns the application state into a given ` desired ` state with the smallest // number of Put / Delete calls .
func (ab *AlgorandBuffer) AchieveDesiredState(ctx context.Context, desired map[string]string) error {
	data, err := ab.GetBuffer(ctx)
	if err != nil {
		return err
	}
	put, del := computeOverlap(desired, data)
	if len(put)+len(del) == 0 {
		return nil
	}
	err = ab.DeleteElements(ctx, getKeys(del)...)
	if err != nil {
		return err
	}
	err = ab.PutElements(ctx, put)
	if err != nil {
		return err
	}
	return nil
}
func ( ab * AlgorandBuffer ) AchieveDesiredState ( ctx context . Context , desired map [ string ] string ) error { data , err := ab . GetBuffer ( ctx ) if err != nil { return err } put , del := computeOverlap ( desired , data ) if len ( put ) + len ( del ) == 0 { return nil } err = ab . DeleteElements ( ctx , getKeys ( del ) ... ) if err != nil { return err } err = ab . PutElements ( ctx , put ) if err != nil { return err } return nil }
AchieveDesiredState turns the application state into a given `desired` state with the smallest
number of Put/Delete calls.
AchieveDesiredState turns the application state into a given ` desired ` state with the smallest number of Put / Delete calls .
// if no changes need to be made, application state is optimal