Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
210952bd
authored
May 15, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: save response time & test time (#59)
parent
d0d3142e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
13 deletions
+46
-13
controller/channel.go
+3
-2
model/channel.go
+12
-1
web/src/components/ChannelsTable.js
+31
-10
No files found.
controller/channel.go
View file @
210952bd
...
@@ -89,7 +89,6 @@ func AddChannel(c *gin.Context) {
...
@@ -89,7 +89,6 @@ func AddChannel(c *gin.Context) {
return
return
}
}
channel
.
CreatedTime
=
common
.
GetTimestamp
()
channel
.
CreatedTime
=
common
.
GetTimestamp
()
channel
.
AccessedTime
=
common
.
GetTimestamp
()
keys
:=
strings
.
Split
(
channel
.
Key
,
"
\n
"
)
keys
:=
strings
.
Split
(
channel
.
Key
,
"
\n
"
)
channels
:=
make
([]
model
.
Channel
,
0
)
channels
:=
make
([]
model
.
Channel
,
0
)
for
_
,
key
:=
range
keys
{
for
_
,
key
:=
range
keys
{
...
@@ -236,7 +235,9 @@ func TestChannel(c *gin.Context) {
...
@@ -236,7 +235,9 @@ func TestChannel(c *gin.Context) {
tik
:=
time
.
Now
()
tik
:=
time
.
Now
()
err
=
testChannel
(
channel
,
chatRequest
)
err
=
testChannel
(
channel
,
chatRequest
)
tok
:=
time
.
Now
()
tok
:=
time
.
Now
()
consumedTime
:=
float64
(
tok
.
Sub
(
tik
)
.
Milliseconds
())
/
1000.0
milliseconds
:=
tok
.
Sub
(
tik
)
.
Milliseconds
()
go
channel
.
UpdateResponseTime
(
milliseconds
)
consumedTime
:=
float64
(
milliseconds
)
/
1000.0
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"success"
:
false
,
...
...
model/channel.go
View file @
210952bd
...
@@ -13,7 +13,8 @@ type Channel struct {
...
@@ -13,7 +13,8 @@ type Channel struct {
Name
string
`json:"name" gorm:"index"`
Name
string
`json:"name" gorm:"index"`
Weight
int
`json:"weight"`
Weight
int
`json:"weight"`
CreatedTime
int64
`json:"created_time" gorm:"bigint"`
CreatedTime
int64
`json:"created_time" gorm:"bigint"`
AccessedTime
int64
`json:"accessed_time" gorm:"bigint"`
TestTime
int64
`json:"test_time" gorm:"bigint"`
ResponseTime
int
`json:"response_time"`
// in milliseconds
BaseURL
string
`json:"base_url" gorm:"column:base_url"`
BaseURL
string
`json:"base_url" gorm:"column:base_url"`
Other
string
`json:"other"`
Other
string
`json:"other"`
}
}
...
@@ -71,6 +72,16 @@ func (channel *Channel) Update() error {
...
@@ -71,6 +72,16 @@ func (channel *Channel) Update() error {
return
err
return
err
}
}
func
(
channel
*
Channel
)
UpdateResponseTime
(
responseTime
int64
)
{
err
:=
DB
.
Model
(
channel
)
.
Select
(
"response_time"
,
"test_time"
)
.
Updates
(
Channel
{
TestTime
:
common
.
GetTimestamp
(),
ResponseTime
:
int
(
responseTime
),
})
.
Error
if
err
!=
nil
{
common
.
SysError
(
"failed to update response time: "
+
err
.
Error
())
}
}
func
(
channel
*
Channel
)
Delete
()
error
{
func
(
channel
*
Channel
)
Delete
()
error
{
var
err
error
var
err
error
err
=
DB
.
Delete
(
channel
)
.
Error
err
=
DB
.
Delete
(
channel
)
.
Error
...
...
web/src/components/ChannelsTable.js
View file @
210952bd
import
React
,
{
useEffect
,
useState
}
from
'react'
;
import
React
,
{
useEffect
,
useState
}
from
'react'
;
import
{
Button
,
Form
,
Label
,
Pagination
,
Popup
,
Table
}
from
'semantic-ui-react'
;
import
{
Button
,
Form
,
Label
,
Pagination
,
Popup
,
Table
}
from
'semantic-ui-react'
;
import
{
Link
}
from
'react-router-dom'
;
import
{
Link
}
from
'react-router-dom'
;
import
{
API
,
copy
,
showError
,
showInfo
,
showSuccess
,
timestamp2string
}
from
'../helpers'
;
import
{
API
,
showError
,
showInfo
,
showSuccess
,
timestamp2string
}
from
'../helpers'
;
import
{
CHANNEL_OPTIONS
,
ITEMS_PER_PAGE
}
from
'../constants'
;
import
{
CHANNEL_OPTIONS
,
ITEMS_PER_PAGE
}
from
'../constants'
;
...
@@ -120,6 +120,22 @@ const ChannelsTable = () => {
...
@@ -120,6 +120,22 @@ const ChannelsTable = () => {
}
}
};
};
const
renderResponseTime
=
(
responseTime
)
=>
{
let
time
=
responseTime
/
1000
;
time
=
time
.
toFixed
(
2
)
+
" 秒"
;
if
(
responseTime
===
0
)
{
return
<
Label
basic
color
=
'grey'
>
未测试
<
/Label>
;
}
else
if
(
responseTime
<=
1000
)
{
return
<
Label
basic
color
=
'green'
>
{
time
}
<
/Label>
;
}
else
if
(
responseTime
<=
3000
)
{
return
<
Label
basic
color
=
'olive'
>
{
time
}
<
/Label>
;
}
else
if
(
responseTime
<=
5000
)
{
return
<
Label
basic
color
=
'yellow'
>
{
time
}
<
/Label>
;
}
else
{
return
<
Label
basic
color
=
'red'
>
{
time
}
<
/Label>
;
}
};
const
searchChannels
=
async
()
=>
{
const
searchChannels
=
async
()
=>
{
if
(
searchKeyword
===
''
)
{
if
(
searchKeyword
===
''
)
{
// if keyword is blank, load files instead.
// if keyword is blank, load files instead.
...
@@ -139,15 +155,20 @@ const ChannelsTable = () => {
...
@@ -139,15 +155,20 @@ const ChannelsTable = () => {
setSearching
(
false
);
setSearching
(
false
);
};
};
const
testChannel
=
async
(
id
,
name
)
=>
{
const
testChannel
=
async
(
id
,
name
,
idx
)
=>
{
const
res
=
await
API
.
get
(
`/api/channel/test/
${
id
}
/`
);
const
res
=
await
API
.
get
(
`/api/channel/test/
${
id
}
/`
);
const
{
success
,
message
,
time
}
=
res
.
data
;
const
{
success
,
message
,
time
}
=
res
.
data
;
if
(
success
)
{
if
(
success
)
{
let
newChannels
=
[...
channels
];
let
realIdx
=
(
activePage
-
1
)
*
ITEMS_PER_PAGE
+
idx
;
newChannels
[
realIdx
].
response_time
=
time
*
1000
;
newChannels
[
realIdx
].
test_time
=
Date
.
now
()
/
1000
;
setChannels
(
newChannels
);
showInfo
(
`通道
${
name
}
测试成功,耗时
${
time
}
秒。`
);
showInfo
(
`通道
${
name
}
测试成功,耗时
${
time
}
秒。`
);
}
else
{
}
else
{
showError
(
message
);
showError
(
message
);
}
}
}
}
;
const
handleKeywordChange
=
async
(
e
,
{
value
})
=>
{
const
handleKeywordChange
=
async
(
e
,
{
value
})
=>
{
setSearchKeyword
(
value
.
trim
());
setSearchKeyword
(
value
.
trim
());
...
@@ -219,18 +240,18 @@ const ChannelsTable = () => {
...
@@ -219,18 +240,18 @@ const ChannelsTable = () => {
<
Table
.
HeaderCell
<
Table
.
HeaderCell
style
=
{{
cursor
:
'pointer'
}}
style
=
{{
cursor
:
'pointer'
}}
onClick
=
{()
=>
{
onClick
=
{()
=>
{
sortChannel
(
'
created
_time'
);
sortChannel
(
'
response
_time'
);
}}
}}
>
>
创建
时间
响应
时间
<
/Table.HeaderCell
>
<
/Table.HeaderCell
>
<
Table
.
HeaderCell
<
Table
.
HeaderCell
style
=
{{
cursor
:
'pointer'
}}
style
=
{{
cursor
:
'pointer'
}}
onClick
=
{()
=>
{
onClick
=
{()
=>
{
sortChannel
(
'
accessed
_time'
);
sortChannel
(
'
test
_time'
);
}}
}}
>
>
访问
时间
测试
时间
<
/Table.HeaderCell
>
<
/Table.HeaderCell
>
<
Table
.
HeaderCell
>
操作
<
/Table.HeaderCell
>
<
Table
.
HeaderCell
>
操作
<
/Table.HeaderCell
>
<
/Table.Row
>
<
/Table.Row
>
...
@@ -250,15 +271,15 @@ const ChannelsTable = () => {
...
@@ -250,15 +271,15 @@ const ChannelsTable = () => {
<
Table
.
Cell
>
{
channel
.
name
?
channel
.
name
:
'无'
}
<
/Table.Cell
>
<
Table
.
Cell
>
{
channel
.
name
?
channel
.
name
:
'无'
}
<
/Table.Cell
>
<
Table
.
Cell
>
{
renderType
(
channel
.
type
)}
<
/Table.Cell
>
<
Table
.
Cell
>
{
renderType
(
channel
.
type
)}
<
/Table.Cell
>
<
Table
.
Cell
>
{
renderStatus
(
channel
.
status
)}
<
/Table.Cell
>
<
Table
.
Cell
>
{
renderStatus
(
channel
.
status
)}
<
/Table.Cell
>
<
Table
.
Cell
>
{
render
Timestamp
(
channel
.
created
_time
)}
<
/Table.Cell
>
<
Table
.
Cell
>
{
render
ResponseTime
(
channel
.
response
_time
)}
<
/Table.Cell
>
<
Table
.
Cell
>
{
renderTimestamp
(
channel
.
accessed_time
)
}
<
/Table.Cell
>
<
Table
.
Cell
>
{
channel
.
test_time
?
renderTimestamp
(
channel
.
test_time
)
:
"未测试"
}
<
/Table.Cell
>
<
Table
.
Cell
>
<
Table
.
Cell
>
<
div
>
<
div
>
<
Button
<
Button
size
=
{
'small'
}
size
=
{
'small'
}
positive
positive
onClick
=
{()
=>
{
onClick
=
{()
=>
{
testChannel
(
channel
.
id
,
channel
.
name
);
testChannel
(
channel
.
id
,
channel
.
name
,
idx
);
}}
}}
>
>
测试
测试
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment