Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
R
railgun-routing-server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
railgun-routing-server
Commits
7bff1021
Commit
7bff1021
authored
Aug 21, 2021
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
85b84cbb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
8 deletions
+11
-8
config/plans.json
config/plans.json
+1
-1
src/Router.ts
src/Router.ts
+10
-7
No files found.
config/plans.json
View file @
7bff1021
[
{
"id"
:
1800
,
"id"
:
3
,
"routers"
:
[
1
,
3
...
...
src/Router.ts
View file @
7bff1021
...
...
@@ -38,7 +38,7 @@ export class Router {
this
.
via
.
set
(
router
,
router
);
}
for
(
const
plan
of
plans
.
filter
(
plan
=>
!
plan
.
routers
.
includes
(
this
.
id
)))
{
this
.
plan
[
plan
.
id
]
=
Router
.
all
.
find
(
r
=>
r
.
id
==
plan
.
routers
[
0
])
!
.
id
;
this
.
plan
[
plan
.
id
]
=
this
.
id
;
}
}
...
...
@@ -112,19 +112,22 @@ export class Router {
}
}
const
changedPlan
:
Record
<
number
,
number
|
null
>
=
{};
// 计算 route plan
// 凡是自己可以作为那个 plan 出口的,是不会计算直接跳过的,所以这里有 plan 到自己的意思是,没有找到任何一个通的可以出的地方,所以只好从自己出了
const
changedPlan
:
Record
<
number
,
number
>
=
{};
for
(
const
plan
of
plans
.
filter
(
plan
=>
!
plan
.
routers
.
includes
(
this
.
id
)))
{
const
currentPlan
=
this
.
plan
[
plan
.
id
];
const
currentMetric
=
const
currentMetric
=
currentPlan
===
this
.
id
?
Infinity
:
metric
[
currentPlan
];
const
items
=
plan
.
routers
.
map
(
to
=>
[
to
,
metric
[
to
]]);
const
[
bestPlan
,
bestMetric
]
=
_
.
minBy
(
items
,
([
t
,
m
])
=>
m
)
!
;
if
(
bestMetric
===
Infinity
)
{
changedPlan
[
plan
.
id
]
=
null
;
}
else
{
if
(
currentPlan
!==
this
.
id
&&
bestMetric
===
Infinity
)
{
// 原来通的,现在不通了
changedPlan
[
plan
.
id
]
=
this
.
id
;
}
else
if
(
currentPlan
!==
bestPlan
&&
bestMetric
+
config
.
throttle
<
currentMetric
)
{
changedPlan
[
plan
.
id
]
=
bestPlan
;
}
}
if
(
!
_
.
isEmpty
(
changedVia
)
||
!
_
.
isEmpty
(
changedPlan
))
{
...
...
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