Skip to content

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 :)

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

@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

Development

Successfully merging this pull request may close these issues.

3 participants