-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Datacache on batch func #1
Conversation
eaglemoor
commented
Apr 3, 2023
- Use Key[K]/Keys[K] in BatchFunc and Loader for save original context
- Add DataCache[K, V] for wrap batchFunc and use cache on real data. It's need for use not in memory caches, like redis.
// Tests | ||
/////////////////////////////////////////////////// | ||
// ///////////////////////////////////////////////// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Кажется, это случайность)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это go fmt :)
dataloader.go
Outdated
func batchWithCache[K comparable, V any](ctx context.Context, batchfn BatchFunc[K, V], keys Keys[K], cache DataCache[K, V]) []*Result[V] { | ||
result := make([]*Result[V], len(keys)) | ||
reqKeys := make(Keys[K], 0, len(keys)) | ||
keyMap := make(map[int]int, len(keys)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А зачем мапка? У тебя же ключ - это индекс reqKeys, который монотонно и непрерывно возрастает, можно на слайс заменить.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Немного переделал код, map тут нужно для организации exist key, если из batchfn придет больше ключей, но со slice мы ляжем с паникой.