<commit_before>package model

type UserGroup interface {
	GetID() int
	GetName() string
	setName(string)
	linkValues() []string
	setLinkValues([]string)
	value() []string
}
type Backend interface {
	// Getter
	FindUserByID(int) (map[string]UserGroup, error)
	FindUserByName(string) (map[string]UserGroup, error)
	FindGroupByID(int) (map[string]UserGroup, error)
	FindGroupByName(string) (map[string]UserGroup, error)
	Users() (map[string]UserGroup, error)
	Groups() (map[string]UserGroup, error)
	HighestUserID() int
	LowestUserID() int
	HighestGroupID() int
	LowestGroupID() int

	// Setter
	CreateUser(UserGroup) error
	DeleteUser(int) error
	UpdateUser(UserGroup) error
	CreateGroup(UserGroup) error
	DeleteGroup(int) error
	UpdateGroup(UserGroup) error
}

func SyncConfig(resourceName string, b Backend, configResources, backendResources map[string]UserGroup) error {
	var backendResource UserGroup
	if configResources != nil {
		for _, cu := range configResources {
			found := false

			if backendResources != nil {
				for _, eu := range backendResources {
					if cu.GetID() == eu.GetID() {
						backendResource = eu
						found = true
						break
					}
				}
			}

			if found {
				if resourceName == "users" {
					// not overwrite password
					cu.(*User).Password = backendResource.(*User).Password

					if err := b.UpdateUser(cu); err != nil {
						return err
					}
				} else {
					if err := b.UpdateGroup(cu); err != nil {
						return err
					}
				}
			} else {
				if resourceName == "users" {<commit_msg>check diff before update<commit_after>package model

import "reflect"

type UserGroup interface {
	GetID() int
	GetName() string
	setName(string)
	linkValues() []string
	setLinkValues([]string)
	value() []string
}
type Backend interface {
	// Getter
	FindUserByID(int) (map[string]UserGroup, error)
	FindUserByName(string) (map[string]UserGroup, error)
	FindGroupByID(int) (map[string]UserGroup, error)
	FindGroupByName(string) (map[string]UserGroup, error)
	Users() (map[string]UserGroup, error)
	Groups() (map[string]UserGroup, error)
	HighestUserID() int
	LowestUserID() int
	HighestGroupID() int
	LowestGroupID() int

	// Setter
	CreateUser(UserGroup) error
	DeleteUser(int) error
	UpdateUser(UserGroup) error
	CreateGroup(UserGroup) error
	DeleteGroup(int) error
	UpdateGroup(UserGroup) error
}

func SyncConfig(resourceName string, b Backend, configResources, backendResources map[string]UserGroup) error {
	var backendResource UserGroup
	if configResources != nil {
		for _, cu := range configResources {
			found := false

			if backendResources != nil {
				for _, eu := range backendResources {
					if cu.GetID() == eu.GetID() {
						backendResource = eu
						found = true
						break
					}
				}
			}

			if found {
				if resourceName == "users" {
					// not overwrite password
					cu.(*User).Password = backendResource.(*User).Password

					if !reflect.DeepEqual(cu.(*User), backendResource.(*User)) {
						if err := b.UpdateUser(cu); err != nil {
							return err
						}
					}
				} else {
					if !reflect.DeepEqual(cu.(*Group), backendResource.(*Group)) {
						if err := b.UpdateGroup(cu); err != nil {
							return err
						}
					}
				}
			} else {
				if resourceName == "users" {
{'fraction_non_alphanumeric': 0.11956856702619414, 'fraction_numerical': 0.0, 'mean_word_length': 3.6571018651362985, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3660645', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1029, 'n_words': 257}