Skip to content
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

Closed
wants to merge 4 commits into from
Closed

Datacache on batch func #1

wants to merge 4 commits into from

Conversation

eaglemoor
Copy link
Owner

  1. Use Key[K]/Keys[K] in BatchFunc and Loader for save original context
  2. 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
///////////////////////////////////////////////////
// /////////////////////////////////////////////////
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется, это случайность)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это go fmt :)

keys.go Show resolved Hide resolved
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))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А зачем мапка? У тебя же ключ - это индекс reqKeys, который монотонно и непрерывно возрастает, можно на слайс заменить.

Copy link
Owner Author

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 мы ляжем с паникой.

dataloader.go Show resolved Hide resolved
@eaglemoor eaglemoor closed this Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants