Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dima Krasner
Sharkey
Commits
d27b3525
Commit
d27b3525
authored
1 year ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
enhance(reversi): improve matching system
parent
7beb4ed1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/backend/src/core/ReversiService.ts
+9
-10
9 additions, 10 deletions
packages/backend/src/core/ReversiService.ts
packages/frontend/src/pages/reversi/index.vue
+2
-0
2 additions, 0 deletions
packages/frontend/src/pages/reversi/index.vue
with
11 additions
and
10 deletions
packages/backend/src/core/ReversiService.ts
+
9
−
10
View file @
d27b3525
...
...
@@ -24,7 +24,7 @@ import { Serialized } from '@/types.js';
import
{
ReversiGameEntityService
}
from
'
./entities/ReversiGameEntityService.js
'
;
import
type
{
OnApplicationShutdown
,
OnModuleInit
}
from
'
@nestjs/common
'
;
const
MATCHING
_TIMEOUT_MS
=
1000
*
20
;
// 20sec
const
INVITATION
_TIMEOUT_MS
=
1000
*
20
;
// 20sec
@
Injectable
()
export
class
ReversiService
implements
OnApplicationShutdown
,
OnModuleInit
{
...
...
@@ -112,7 +112,7 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit {
//#region 相手から既に招待されてないか確認
const
invitations
=
await
this
.
redisClient
.
zrange
(
`reversi:matchSpecific:
${
me
.
id
}
`
,
Date
.
now
()
-
MATCHING
_TIMEOUT_MS
,
Date
.
now
()
-
INVITATION
_TIMEOUT_MS
,
'
+inf
'
,
'
BYSCORE
'
);
...
...
@@ -157,7 +157,7 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit {
//#region まず自分宛ての招待を探す
const
invitations
=
await
this
.
redisClient
.
zrange
(
`reversi:matchSpecific:
${
me
.
id
}
`
,
Date
.
now
()
-
MATCHING
_TIMEOUT_MS
,
Date
.
now
()
-
INVITATION
_TIMEOUT_MS
,
'
+inf
'
,
'
BYSCORE
'
);
...
...
@@ -173,15 +173,14 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit {
const
matchings
=
await
this
.
redisClient
.
zrange
(
'
reversi:matchAny
'
,
Date
.
now
()
-
MATCHING_TIMEOUT_MS
,
'
+inf
'
,
'
BYSCO
RE
'
);
0
,
2
,
// 自分自身のIDが入っている場合もあるので2つ取得
'
RE
V
'
);
const
userIds
=
matchings
.
filter
(
id
=>
id
!==
me
.
id
);
if
(
userIds
.
length
>
0
)
{
// pick random
const
matchedUserId
=
userIds
[
Math
.
floor
(
Math
.
random
()
*
userIds
.
length
)];
const
matchedUserId
=
userIds
[
0
];
await
this
.
redisClient
.
zrem
(
'
reversi:matchAny
'
,
me
.
id
,
matchedUserId
);
...
...
@@ -191,7 +190,7 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit {
}
else
{
const
redisPipeline
=
this
.
redisClient
.
pipeline
();
redisPipeline
.
zadd
(
'
reversi:matchAny
'
,
Date
.
now
(),
me
.
id
);
redisPipeline
.
expire
(
'
reversi:matchAny
'
,
1
20
,
'
NX
'
);
redisPipeline
.
expire
(
'
reversi:matchAny
'
,
1
5
,
'
NX
'
);
await
redisPipeline
.
exec
();
return
null
;
}
...
...
@@ -380,7 +379,7 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit {
public
async
getInvitations
(
user
:
MiUser
):
Promise
<
MiUser
[
'
id
'
][]
>
{
const
invitations
=
await
this
.
redisClient
.
zrange
(
`reversi:matchSpecific:
${
user
.
id
}
`
,
Date
.
now
()
-
MATCHING
_TIMEOUT_MS
,
Date
.
now
()
-
INVITATION
_TIMEOUT_MS
,
'
+inf
'
,
'
BYSCORE
'
);
return
invitations
;
...
...
This diff is collapsed.
Click to expand it.
packages/frontend/src/pages/reversi/index.vue
+
2
−
0
View file @
d27b3525
...
...
@@ -230,6 +230,8 @@ onMounted(() => {
misskeyApi
(
'
reversi/invitations
'
).
then
(
_invitations
=>
{
invitations
.
value
=
_invitations
;
});
window
.
addEventListener
(
'
beforeunload
'
,
cancelMatching
);
});
onDeactivated
(()
=>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment