Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
srvpro
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
nanahira
srvpro
Commits
3aa26a21
Commit
3aa26a21
authored
Nov 15, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve random replay
parent
f3144a23
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
12 deletions
+23
-12
data-manager/DataManager.js
data-manager/DataManager.js
+11
-6
data-manager/DataManager.ts
data-manager/DataManager.ts
+12
-6
No files found.
data-manager/DataManager.js
View file @
3aa26a21
...
@@ -74,8 +74,17 @@ class DataManager {
...
@@ -74,8 +74,17 @@ class DataManager {
}
}
async
getRandomCloudReplay
()
{
async
getRandomCloudReplay
()
{
try
{
try
{
const
[
minQuery
,
maxQuery
]
=
await
Promise
.
all
([
"
min
"
,
"
max
"
].
map
(
minOrMax
=>
this
.
db
.
createQueryBuilder
()
.
select
(
`
${
minOrMax
}
(id)`
,
"
value
"
)
.
from
(
CloudReplay_1
.
CloudReplay
,
"
replay
"
)
.
getRawOne
()));
if
(
!
minQuery
||
maxQuery
)
{
return
null
;
}
const
targetId
=
Math
.
floor
((
maxQuery
.
value
-
minQuery
.
value
)
*
Math
.
random
())
+
minQuery
.
value
;
return
await
this
.
db
.
createQueryBuilder
(
CloudReplay_1
.
CloudReplay
,
"
replay
"
)
return
await
this
.
db
.
createQueryBuilder
(
CloudReplay_1
.
CloudReplay
,
"
replay
"
)
.
orderBy
(
"
rand()
"
)
.
where
(
"
replay.id >= :targetId
"
,
{
targetId
})
.
orderBy
(
"
replay.id
"
,
"
ASC
"
)
.
limit
(
4
)
//there may be 4 players
.
limit
(
4
)
//there may be 4 players
.
leftJoinAndSelect
(
"
replay.players
"
,
"
player
"
)
.
leftJoinAndSelect
(
"
replay.players
"
,
"
player
"
)
.
getOne
();
.
getOne
();
...
@@ -329,11 +338,7 @@ class DataManager {
...
@@ -329,11 +338,7 @@ class DataManager {
return
user
?
user
.
chatColor
:
null
;
return
user
?
user
.
chatColor
:
null
;
}
}
async
setUserChatColor
(
key
,
color
)
{
async
setUserChatColor
(
key
,
color
)
{
let
user
=
await
this
.
getUser
(
key
);
let
user
=
await
this
.
getOrCreateUser
(
key
);
if
(
!
user
)
{
user
=
new
User_1
.
User
();
user
.
key
=
key
;
}
user
.
chatColor
=
color
;
user
.
chatColor
=
color
;
return
await
this
.
saveUser
(
user
);
return
await
this
.
saveUser
(
user
);
}
}
...
...
data-manager/DataManager.ts
View file @
3aa26a21
...
@@ -96,8 +96,18 @@ export class DataManager {
...
@@ -96,8 +96,18 @@ export class DataManager {
async
getRandomCloudReplay
()
{
async
getRandomCloudReplay
()
{
try
{
try
{
const
[
minQuery
,
maxQuery
]
=
await
Promise
.
all
([
"
min
"
,
"
max
"
].
map
(
minOrMax
=>
this
.
db
.
createQueryBuilder
()
.
select
(
`
${
minOrMax
}
(id)`
,
"
value
"
)
.
from
(
CloudReplay
,
"
replay
"
)
.
getRawOne
()
));
if
(
!
minQuery
||
maxQuery
)
{
return
null
;
}
const
targetId
=
Math
.
floor
((
maxQuery
.
value
-
minQuery
.
value
)
*
Math
.
random
())
+
minQuery
.
value
;
return
await
this
.
db
.
createQueryBuilder
(
CloudReplay
,
"
replay
"
)
return
await
this
.
db
.
createQueryBuilder
(
CloudReplay
,
"
replay
"
)
.
orderBy
(
"
rand()
"
)
.
where
(
"
replay.id >= :targetId
"
,
{
targetId
})
.
orderBy
(
"
replay.id
"
,
"
ASC
"
)
.
limit
(
4
)
//there may be 4 players
.
limit
(
4
)
//there may be 4 players
.
leftJoinAndSelect
(
"
replay.players
"
,
"
player
"
)
.
leftJoinAndSelect
(
"
replay.players
"
,
"
player
"
)
.
getOne
();
.
getOne
();
...
@@ -353,11 +363,7 @@ export class DataManager {
...
@@ -353,11 +363,7 @@ export class DataManager {
return
user
?
user
.
chatColor
:
null
;
return
user
?
user
.
chatColor
:
null
;
}
}
async
setUserChatColor
(
key
:
string
,
color
:
string
)
{
async
setUserChatColor
(
key
:
string
,
color
:
string
)
{
let
user
=
await
this
.
getUser
(
key
);
let
user
=
await
this
.
getOrCreateUser
(
key
);
if
(
!
user
)
{
user
=
new
User
();
user
.
key
=
key
;
}
user
.
chatColor
=
color
;
user
.
chatColor
=
color
;
return
await
this
.
saveUser
(
user
);
return
await
this
.
saveUser
(
user
);
}
}
...
...
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