mirror of https://github.com/portainer/portainer
fix(edge-stack): URI too large error for edge stacks with a large amount of environments [EE-5583] (#9085)
* refactor(edge-stacks): filter endpoints by edgeStack * feat(api/endpoints): edge stack filter support filtering on status in stack * refactor(endpoints): use separate query params and not JSON query param when querying for an edge stack * feat(api/endpoints): handle stack filter on dynamic groups + unique list with multiple groups sharing environments * fix(app/endpoints): edge stack related query params type definition * fix(api/endpoints): rebase conflicts on importspull/9105/head
parent
223dfe89dd
commit
2eca5e05d4
@ -0,0 +1,41 @@
|
||||
package unique
|
||||
|
||||
func Unique[T comparable](items []T) []T {
|
||||
return UniqueBy(items, func(item T) T {
|
||||
return item
|
||||
})
|
||||
}
|
||||
|
||||
func UniqueBy[ItemType any, ComparableType comparable](items []ItemType, accessorFunc func(ItemType) ComparableType) []ItemType {
|
||||
includedItems := make(map[ComparableType]bool)
|
||||
result := []ItemType{}
|
||||
|
||||
for _, item := range items {
|
||||
if _, isIncluded := includedItems[accessorFunc(item)]; !isIncluded {
|
||||
includedItems[accessorFunc(item)] = true
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
type someType struct {
|
||||
id int
|
||||
fn func()
|
||||
}
|
||||
|
||||
func Test() {
|
||||
ids := []int{1, 2, 3, 3}
|
||||
_ = UniqueBy(ids, func(id int) int { return id })
|
||||
_ = Unique(ids) // shorthand for UniqueBy Identity/self
|
||||
|
||||
as := []someType{{id: 1}, {id: 2}, {id: 3}, {id: 3}}
|
||||
_ = UniqueBy(as, func(item someType) int { return item.id }) // no error
|
||||
_ = UniqueBy(as, func(item someType) someType { return item }) // compile error - someType is not comparable
|
||||
_ = Unique(as) // compile error - shorthand fails for the same reason
|
||||
}
|
||||
|
||||
*/
|
Loading…
Reference in new issue