summaryrefslogtreecommitdiffstats
path: root/modules/queue
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-03-01 21:08:10 +0000
committerGitHub <noreply@github.com>2021-03-01 22:08:10 +0100
commitf0e15250b9e322cc7731ba026d12387c2b549a42 (patch)
treef13d46119077ba924d620ef172b91daa315bda0a /modules/queue
parent59fd641d1fb021e35aea7f9f4a1916cc11ef5c51 (diff)
downloadgitea-f0e15250b9e322cc7731ba026d12387c2b549a42.tar.gz
gitea-f0e15250b9e322cc7731ba026d12387c2b549a42.zip
Migrate to use jsoniter instead of encoding/json (#14841)
* Migrate to use jsoniter * fix tests * update gitea.com/go-chi/binding Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'modules/queue')
-rw-r--r--modules/queue/helper.go5
-rw-r--r--modules/queue/manager.go3
-rw-r--r--modules/queue/queue_bytefifo.go4
-rw-r--r--modules/queue/queue_test.go3
-rw-r--r--modules/queue/setting.go3
5 files changed, 13 insertions, 5 deletions
diff --git a/modules/queue/helper.go b/modules/queue/helper.go
index 751e0cfadc..161c2fe8e7 100644
--- a/modules/queue/helper.go
+++ b/modules/queue/helper.go
@@ -5,8 +5,9 @@
package queue
import (
- "encoding/json"
"reflect"
+
+ jsoniter "github.com/json-iterator/go"
)
// Mappable represents an interface that can MapTo another interface
@@ -19,6 +20,7 @@ type Mappable interface {
// It will tolerate the cfg being passed as a []byte or string of a json representation of the
// exemplar or the correct type of the exemplar itself
func toConfig(exemplar, cfg interface{}) (interface{}, error) {
+ json := jsoniter.ConfigCompatibleWithStandardLibrary
// First of all check if we've got the same type as the exemplar - if so it's all fine.
if reflect.TypeOf(cfg).AssignableTo(reflect.TypeOf(exemplar)) {
@@ -66,6 +68,7 @@ func toConfig(exemplar, cfg interface{}) (interface{}, error) {
// unmarshalAs will attempt to unmarshal provided bytes as the provided exemplar
func unmarshalAs(bs []byte, exemplar interface{}) (data Data, err error) {
+ json := jsoniter.ConfigCompatibleWithStandardLibrary
if exemplar != nil {
t := reflect.TypeOf(exemplar)
n := reflect.New(t)
diff --git a/modules/queue/manager.go b/modules/queue/manager.go
index 3e9f8fc8db..d44007a0f0 100644
--- a/modules/queue/manager.go
+++ b/modules/queue/manager.go
@@ -6,7 +6,6 @@ package queue
import (
"context"
- "encoding/json"
"fmt"
"reflect"
"sort"
@@ -14,6 +13,7 @@ import (
"time"
"code.gitea.io/gitea/modules/log"
+ jsoniter "github.com/json-iterator/go"
)
var manager *Manager
@@ -110,6 +110,7 @@ func (m *Manager) Add(managed interface{},
configuration,
exemplar interface{}) int64 {
+ json := jsoniter.ConfigCompatibleWithStandardLibrary
cfg, _ := json.Marshal(configuration)
mq := &ManagedQueue{
Type: t,
diff --git a/modules/queue/queue_bytefifo.go b/modules/queue/queue_bytefifo.go
index 4bb7bbf2b1..fe5178ff2d 100644
--- a/modules/queue/queue_bytefifo.go
+++ b/modules/queue/queue_bytefifo.go
@@ -6,12 +6,12 @@ package queue
import (
"context"
- "encoding/json"
"fmt"
"sync"
"time"
"code.gitea.io/gitea/modules/log"
+ jsoniter "github.com/json-iterator/go"
)
// ByteFIFOQueueConfiguration is the configuration for a ByteFIFOQueue
@@ -71,6 +71,7 @@ func (q *ByteFIFOQueue) PushFunc(data Data, fn func() error) error {
if !assignableTo(data, q.exemplar) {
return fmt.Errorf("Unable to assign data: %v to same type as exemplar: %v in %s", data, q.exemplar, q.name)
}
+ json := jsoniter.ConfigCompatibleWithStandardLibrary
bs, err := json.Marshal(data)
if err != nil {
return err
@@ -229,6 +230,7 @@ func (q *ByteFIFOUniqueQueue) Has(data Data) (bool, error) {
if !assignableTo(data, q.exemplar) {
return false, fmt.Errorf("Unable to assign data: %v to same type as exemplar: %v in %s", data, q.exemplar, q.name)
}
+ json := jsoniter.ConfigCompatibleWithStandardLibrary
bs, err := json.Marshal(data)
if err != nil {
return false, err
diff --git a/modules/queue/queue_test.go b/modules/queue/queue_test.go
index 3608f68d3d..89ce23ac4c 100644
--- a/modules/queue/queue_test.go
+++ b/modules/queue/queue_test.go
@@ -5,9 +5,9 @@
package queue
import (
- "encoding/json"
"testing"
+ jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
@@ -30,6 +30,7 @@ func TestToConfig(t *testing.T) {
assert.NotEqual(t, cfg2, exemplar)
assert.Equal(t, &cfg, &cfg2)
+ json := jsoniter.ConfigCompatibleWithStandardLibrary
cfgString, err := json.Marshal(cfg)
assert.NoError(t, err)
diff --git a/modules/queue/setting.go b/modules/queue/setting.go
index 9ee1af8c7d..9b2c31b783 100644
--- a/modules/queue/setting.go
+++ b/modules/queue/setting.go
@@ -5,12 +5,12 @@
package queue
import (
- "encoding/json"
"fmt"
"strings"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
+ jsoniter "github.com/json-iterator/go"
)
func validType(t string) (Type, error) {
@@ -28,6 +28,7 @@ func validType(t string) (Type, error) {
func getQueueSettings(name string) (setting.QueueSettings, []byte) {
q := setting.GetQueueSettings(name)
+ json := jsoniter.ConfigCompatibleWithStandardLibrary
cfg, err := json.Marshal(q)
if err != nil {
log.Error("Unable to marshall generic options: %v Error: %v", q, err)