Skip to content

Commit

Permalink
api gzip
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Nov 24, 2023
1 parent f3b1ed8 commit 3a09174
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
15 changes: 13 additions & 2 deletions pkg/api/response.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"compress/gzip"
"encoding/json"
"net/http"
)
Expand All @@ -21,6 +22,16 @@ func (r *Response) OutJson(w http.ResponseWriter, code int, msg string, data any
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write(jsonData)

//w.Header().Set("Content-Type", "application/json")
//_, _ = w.Write(jsonData)

w.Header().Set("Content-Encoding", "gzip")

gw := gzip.NewWriter(w)
defer func() {
_ = gw.Close()
}()

_, _ = gw.Write(jsonData)
}
2 changes: 2 additions & 0 deletions pkg/queue/group_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (q *GroupQueue) Enqueue(key string, value any, priority int64) {
func (q *GroupQueue) Get(key string) (items []*Item) {
q.mutex.RLock()
defer q.mutex.RUnlock()

if key == "" {
for _, v := range q.data {
item, _ := v.GetItemN(-1)
Expand All @@ -47,6 +48,7 @@ func (q *GroupQueue) Get(key string) (items []*Item) {
func (q *GroupQueue) Size(key string) int {
q.mutex.RLock()
defer q.mutex.RUnlock()

if key == "" {
var l int
for _, v := range q.data {
Expand Down
2 changes: 1 addition & 1 deletion web/ui/src/requests/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const api = async () => {
'Content-Type': 'application/json',
'X-API-Key': userStore.useUserStore().user.token,
},
timeout: 5000
timeout: 10000
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions web/ui/src/views/RecordsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,12 @@ const refresh = () => {
}
refresh()
if (checked1.value) {
interval = setInterval(refresh, 1000)
interval = setInterval(refresh, 2000)
}
const changeSwitch = () => {
if (checked1.value) {
if (!checked1Disable.value) {
interval = setInterval(refresh, 1000)
interval = setInterval(refresh, 2000)
}
checked1Disable.value = true
} else {
Expand Down
4 changes: 2 additions & 2 deletions web/ui/src/views/RequestsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,12 @@ const refresh = () => {
}
refresh()
if (checked1.value) {
interval = setInterval(refresh, 1000)
interval = setInterval(refresh, 2000)
}
const changeSwitch = () => {
if (checked1.value) {
if (!checked1Disable.value) {
interval = setInterval(refresh, 1000)
interval = setInterval(refresh, 2000)
}
checked1Disable.value = true
} else {
Expand Down

0 comments on commit 3a09174

Please sign in to comment.