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
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
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
MyCard
srvpro
Commits
416af402
Commit
416af402
authored
Nov 15, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update transaction
parent
f308299e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
20 deletions
+40
-20
data-manager/DataManager.ts
data-manager/DataManager.ts
+40
-20
No files found.
data-manager/DataManager.ts
View file @
416af402
import
moment
from
"
moment
"
;
import
moment
from
"
moment
"
;
import
bunyan
from
"
bunyan
"
;
import
bunyan
from
"
bunyan
"
;
import
{
Connection
,
ConnectionOptions
,
createConnection
}
from
"
typeorm
"
;
import
{
Connection
,
ConnectionOptions
,
createConnection
,
EntityManager
}
from
"
typeorm
"
;
import
{
CloudReplay
}
from
"
./entities/CloudReplay
"
;
import
{
CloudReplay
}
from
"
./entities/CloudReplay
"
;
import
{
CloudReplayPlayer
}
from
"
./entities/CloudReplayPlayer
"
;
import
{
CloudReplayPlayer
}
from
"
./entities/CloudReplayPlayer
"
;
import
{
Ban
}
from
"
./entities/Ban
"
;
import
{
Ban
}
from
"
./entities/Ban
"
;
...
@@ -43,6 +43,23 @@ export class DataManager {
...
@@ -43,6 +43,23 @@ export class DataManager {
this
.
ready
=
false
;
this
.
ready
=
false
;
this
.
log
=
log
;
this
.
log
=
log
;
}
}
private
async
transaction
(
fun
:
(
mdb
:
EntityManager
)
=>
Promise
<
boolean
>
)
{
const
runner
=
await
this
.
db
.
createQueryRunner
();
await
runner
.
connect
();
await
runner
.
startTransaction
();
let
result
=
false
;
try
{
result
=
await
fun
(
runner
.
manager
);
}
catch
(
e
)
{
result
=
false
;
this
.
log
.
warn
(
`Failed running transaction:
${
e
.
toString
()}
`
)
}
if
(
result
)
{
await
runner
.
commitTransaction
();
}
else
{
await
runner
.
rollbackTransaction
();
}
}
async
init
()
{
async
init
()
{
this
.
db
=
await
createConnection
({
this
.
db
=
await
createConnection
({
type
:
"
mysql
"
,
type
:
"
mysql
"
,
...
@@ -99,15 +116,17 @@ export class DataManager {
...
@@ -99,15 +116,17 @@ export class DataManager {
const
player
=
CloudReplayPlayer
.
fromPlayerInfo
(
p
);
const
player
=
CloudReplayPlayer
.
fromPlayerInfo
(
p
);
return
player
;
return
player
;
});
});
await
this
.
db
.
transaction
(
async
(
mdb
)
=>
{
await
this
.
transaction
(
async
(
mdb
)
=>
{
try
{
try
{
const
nreplay
=
await
mdb
.
save
(
replay
);
const
nreplay
=
await
mdb
.
save
(
replay
);
for
(
let
player
of
players
)
{
for
(
let
player
of
players
)
{
player
.
cloudReplay
=
nreplay
;
player
.
cloudReplay
=
nreplay
;
}
}
await
mdb
.
save
(
players
);
await
mdb
.
save
(
players
);
return
true
;
}
catch
(
e
)
{
}
catch
(
e
)
{
this
.
log
.
warn
(
`Failed to save replay R#
${
replay
.
id
}
:
${
e
.
toString
()}
`
);
this
.
log
.
warn
(
`Failed to save replay R#
${
replay
.
id
}
:
${
e
.
toString
()}
`
);
return
false
;
}
}
});
});
}
}
...
@@ -262,7 +281,6 @@ export class DataManager {
...
@@ -262,7 +281,6 @@ export class DataManager {
return
allDuelLogs
.
map
(
duelLog
=>
duelLog
.
replayFileName
);
return
allDuelLogs
.
map
(
duelLog
=>
duelLog
.
replayFileName
);
}
}
async
clearDuelLog
()
{
async
clearDuelLog
()
{
//await this.db.transaction(async (mdb) => {
const
runner
=
this
.
db
.
createQueryRunner
();
const
runner
=
this
.
db
.
createQueryRunner
();
try
{
try
{
await
runner
.
connect
();
await
runner
.
connect
();
...
@@ -276,7 +294,6 @@ export class DataManager {
...
@@ -276,7 +294,6 @@ export class DataManager {
await
runner
.
rollbackTransaction
();
await
runner
.
rollbackTransaction
();
this
.
log
.
warn
(
`Failed to clear duel logs:
${
e
.
toString
()}
`
);
this
.
log
.
warn
(
`Failed to clear duel logs:
${
e
.
toString
()}
`
);
}
}
//});
}
}
async
saveDuelLog
(
name
:
string
,
roomId
:
number
,
cloudReplayId
:
number
,
replayFilename
:
string
,
roomMode
:
number
,
duelCount
:
number
,
playerInfos
:
DuelLogPlayerInfo
[])
{
async
saveDuelLog
(
name
:
string
,
roomId
:
number
,
cloudReplayId
:
number
,
replayFilename
:
string
,
roomMode
:
number
,
duelCount
:
number
,
playerInfos
:
DuelLogPlayerInfo
[])
{
const
duelLog
=
new
DuelLog
();
const
duelLog
=
new
DuelLog
();
...
@@ -288,15 +305,17 @@ export class DataManager {
...
@@ -288,15 +305,17 @@ export class DataManager {
duelLog
.
roomMode
=
roomMode
;
duelLog
.
roomMode
=
roomMode
;
duelLog
.
duelCount
=
duelCount
;
duelLog
.
duelCount
=
duelCount
;
const
players
=
playerInfos
.
map
(
p
=>
DuelLogPlayer
.
fromDuelLogPlayerInfo
(
p
));
const
players
=
playerInfos
.
map
(
p
=>
DuelLogPlayer
.
fromDuelLogPlayerInfo
(
p
));
await
this
.
db
.
transaction
(
async
(
mdb
)
=>
{
await
this
.
transaction
(
async
(
mdb
)
=>
{
try
{
try
{
const
savedDuelLog
=
await
mdb
.
save
(
duelLog
);
const
savedDuelLog
=
await
mdb
.
save
(
duelLog
);
for
(
let
player
of
players
)
{
for
(
let
player
of
players
)
{
player
.
duelLog
=
savedDuelLog
;
player
.
duelLog
=
savedDuelLog
;
}
}
await
mdb
.
save
(
players
);
await
mdb
.
save
(
players
);
return
true
;
}
catch
(
e
)
{
}
catch
(
e
)
{
this
.
log
.
warn
(
`Failed to save duel log
${
name
}
:
${
e
.
toString
()}
`
);
this
.
log
.
warn
(
`Failed to save duel log
${
name
}
:
${
e
.
toString
()}
`
);
return
false
;
}
}
});
});
...
@@ -344,7 +363,7 @@ export class DataManager {
...
@@ -344,7 +363,7 @@ export class DataManager {
}
}
async
migrateChatColors
(
data
:
any
)
{
async
migrateChatColors
(
data
:
any
)
{
await
this
.
db
.
transaction
(
async
(
mdb
)
=>
{
await
this
.
transaction
(
async
(
mdb
)
=>
{
try
{
try
{
const
users
:
User
[]
=
[];
const
users
:
User
[]
=
[];
for
(
let
key
in
data
)
{
for
(
let
key
in
data
)
{
...
@@ -358,9 +377,10 @@ export class DataManager {
...
@@ -358,9 +377,10 @@ export class DataManager {
users
.
push
(
user
);
users
.
push
(
user
);
}
}
await
mdb
.
save
(
users
);
await
mdb
.
save
(
users
);
return
true
;
}
catch
(
e
)
{
}
catch
(
e
)
{
this
.
log
.
warn
(
`Failed to migrate chat color data:
${
e
.
toString
()}
`
);
this
.
log
.
warn
(
`Failed to migrate chat color data:
${
e
.
toString
()}
`
);
return
null
;
return
false
;
}
}
});
});
...
...
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