summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-01-17 14:54:30 +0000
committerLibravatar GitHub <noreply@github.com>2024-01-17 14:54:30 +0000
commit906639ad7eb92e9d631599f78979908930e59c84 (patch)
treedfef6d0a5ba47c49c214e4537a89dee6ad528df8 /internal
parent[bugfix] Better Postgres search case insensitivity (#2526) (diff)
downloadgotosocial-906639ad7eb92e9d631599f78979908930e59c84.tar.xz
[chore] update viper version (#2539)
* update viper version * removes our last uses of the slice package * fix tests
Diffstat (limited to 'internal')
-rw-r--r--internal/api/client/accounts/accountupdate.go14
-rw-r--r--internal/api/client/streaming/stream.go2
-rw-r--r--internal/cache/slice.go3
-rw-r--r--internal/db/bundb/list_test.go26
-rw-r--r--internal/db/bundb/timeline.go14
-rw-r--r--internal/processing/admin/actions.go14
6 files changed, 57 insertions, 16 deletions
diff --git a/internal/api/client/accounts/accountupdate.go b/internal/api/client/accounts/accountupdate.go
index ab731bd7e..41f76adf5 100644
--- a/internal/api/client/accounts/accountupdate.go
+++ b/internal/api/client/accounts/accountupdate.go
@@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"net/http"
+ "slices"
"strconv"
"github.com/gin-gonic/gin"
@@ -30,7 +31,6 @@ import (
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
- "golang.org/x/exp/slices"
)
// AccountUpdateCredentialsPATCHHandler swagger:operation PATCH /api/v1/accounts/update_credentials accountUpdate
@@ -283,8 +283,16 @@ func parseFieldsAttributesFromJSON(jsonFieldsAttributes *map[string]apimodel.Upd
}
// Sort slice by the key each field was submitted with.
- slices.SortFunc(fieldsAttributes, func(a, b apimodel.UpdateField) bool {
- return a.Key < b.Key
+ slices.SortFunc(fieldsAttributes, func(a, b apimodel.UpdateField) int {
+ const k = +1
+ switch {
+ case a.Key > b.Key:
+ return +k
+ case a.Key < b.Key:
+ return -k
+ default:
+ return 0
+ }
})
return &fieldsAttributes, nil
diff --git a/internal/api/client/streaming/stream.go b/internal/api/client/streaming/stream.go
index 2d1c48341..266b64976 100644
--- a/internal/api/client/streaming/stream.go
+++ b/internal/api/client/streaming/stream.go
@@ -19,6 +19,7 @@ package streaming
import (
"context"
+ "slices"
"time"
"codeberg.org/gruf/go-kv"
@@ -28,7 +29,6 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
streampkg "github.com/superseriousbusiness/gotosocial/internal/stream"
- "golang.org/x/exp/slices"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
diff --git a/internal/cache/slice.go b/internal/cache/slice.go
index bcc0b68cc..0a7a6ccdc 100644
--- a/internal/cache/slice.go
+++ b/internal/cache/slice.go
@@ -18,8 +18,9 @@
package cache
import (
+ "slices"
+
"codeberg.org/gruf/go-cache/v3/simple"
- "golang.org/x/exp/slices"
)
// SliceCache wraps a simple.Cache to provide simple loader-callback
diff --git a/internal/db/bundb/list_test.go b/internal/db/bundb/list_test.go
index ca078d086..9c5fb2c76 100644
--- a/internal/db/bundb/list_test.go
+++ b/internal/db/bundb/list_test.go
@@ -19,13 +19,13 @@ package bundb_test
import (
"context"
+ "slices"
"testing"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
- "golang.org/x/exp/slices"
)
type ListTestSuite struct {
@@ -43,8 +43,16 @@ func (suite *ListTestSuite) testStructs() (*gtsmodel.List, *gtsmodel.Account) {
}
// Sort by ID descending (again, as we'd expect from the db).
- slices.SortFunc(entries, func(a, b *gtsmodel.ListEntry) bool {
- return b.ID < a.ID
+ slices.SortFunc(entries, func(a, b *gtsmodel.ListEntry) int {
+ const k = -1
+ switch {
+ case a.ID > b.ID:
+ return +k
+ case a.ID < b.ID:
+ return -k
+ default:
+ return 0
+ }
})
testList.ListEntries = entries
@@ -239,8 +247,16 @@ func (suite *ListTestSuite) TestPutListEntries() {
// Add these entries to the test list, sort it again
// to reflect what we'd expect to get from the db.
testList.ListEntries = append(testList.ListEntries, listEntries...)
- slices.SortFunc(testList.ListEntries, func(a, b *gtsmodel.ListEntry) bool {
- return b.ID < a.ID
+ slices.SortFunc(testList.ListEntries, func(a, b *gtsmodel.ListEntry) int {
+ const k = -1
+ switch {
+ case a.ID > b.ID:
+ return +k
+ case a.ID < b.ID:
+ return -k
+ default:
+ return 0
+ }
})
// Now get all list entries from the db.
diff --git a/internal/db/bundb/timeline.go b/internal/db/bundb/timeline.go
index a07f1a844..4af17fb7f 100644
--- a/internal/db/bundb/timeline.go
+++ b/internal/db/bundb/timeline.go
@@ -21,6 +21,7 @@ import (
"context"
"errors"
"fmt"
+ "slices"
"time"
"github.com/superseriousbusiness/gotosocial/internal/db"
@@ -31,7 +32,6 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/state"
"github.com/uptrace/bun"
- "golang.org/x/exp/slices"
)
type timelineDB struct {
@@ -311,8 +311,16 @@ func (t *timelineDB) GetFavedTimeline(ctx context.Context, accountID string, max
}
// Sort by favourite ID rather than status ID
- slices.SortFunc(faves, func(a, b *gtsmodel.StatusFave) bool {
- return a.ID > b.ID
+ slices.SortFunc(faves, func(a, b *gtsmodel.StatusFave) int {
+ const k = -1
+ switch {
+ case a.ID > b.ID:
+ return +k
+ case a.ID < b.ID:
+ return -k
+ default:
+ return 0
+ }
})
statuses := make([]*gtsmodel.Status, 0, len(faves))
diff --git a/internal/processing/admin/actions.go b/internal/processing/admin/actions.go
index b85f05065..0c959b1c5 100644
--- a/internal/processing/admin/actions.go
+++ b/internal/processing/admin/actions.go
@@ -19,6 +19,7 @@ package admin
import (
"context"
+ "slices"
"sync"
"time"
@@ -26,7 +27,6 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/state"
- "golang.org/x/exp/slices"
)
func errActionConflict(action *gtsmodel.AdminAction) gtserror.WithCode {
@@ -140,8 +140,16 @@ func (a *Actions) GetRunning() []*gtsmodel.AdminAction {
// Order by ID descending (creation date).
slices.SortFunc(
running,
- func(a *gtsmodel.AdminAction, b *gtsmodel.AdminAction) bool {
- return a.ID > b.ID
+ func(a *gtsmodel.AdminAction, b *gtsmodel.AdminAction) int {
+ const k = -1
+ switch {
+ case a.ID > b.ID:
+ return +k
+ case a.ID < b.ID:
+ return -k
+ default:
+ return 0
+ }
},
)