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
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
Hide 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
bunyan
from
"
bunyan
"
;
import
{
Connection
,
ConnectionOptions
,
createConnection
}
from
"
typeorm
"
;
import
{
Connection
,
ConnectionOptions
,
createConnection
,
EntityManager
}
from
"
typeorm
"
;
import
{
CloudReplay
}
from
"
./entities/CloudReplay
"
;
import
{
CloudReplayPlayer
}
from
"
./entities/CloudReplayPlayer
"
;
import
{
Ban
}
from
"
./entities/Ban
"
;
...
...
@@ -43,6 +43,23 @@ export class DataManager {
this
.
ready
=
false
;
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
()
{
this
.
db
=
await
createConnection
({
type
:
"
mysql
"
,
...
...
@@ -99,15 +116,17 @@ export class DataManager {
const
player
=
CloudReplayPlayer
.
fromPlayerInfo
(
p
);
return
player
;
});
await
this
.
db
.
transaction
(
async
(
mdb
)
=>
{
await
this
.
transaction
(
async
(
mdb
)
=>
{
try
{
const
nreplay
=
await
mdb
.
save
(
replay
);
for
(
let
player
of
players
)
{
player
.
cloudReplay
=
nreplay
;
}
await
mdb
.
save
(
players
);
return
true
;
}
catch
(
e
)
{
this
.
log
.
warn
(
`Failed to save replay R#
${
replay
.
id
}
:
${
e
.
toString
()}
`
);
return
false
;
}
});
}
...
...
@@ -262,21 +281,19 @@ export class DataManager {
return
allDuelLogs
.
map
(
duelLog
=>
duelLog
.
replayFileName
);
}
async
clearDuelLog
()
{
//await this.db.transaction(async (mdb) => {
const
runner
=
this
.
db
.
createQueryRunner
();
try
{
await
runner
.
connect
();
await
runner
.
startTransaction
();
await
runner
.
query
(
"
SET FOREIGN_KEY_CHECKS = 0;
"
);
await
runner
.
clearTable
(
"
duel_log_player
"
);
await
runner
.
clearTable
(
"
duel_log
"
);
await
runner
.
query
(
"
SET FOREIGN_KEY_CHECKS = 1;
"
);
await
runner
.
commitTransaction
();
}
catch
(
e
)
{
await
runner
.
rollbackTransaction
();
this
.
log
.
warn
(
`Failed to clear duel logs:
${
e
.
toString
()}
`
);
}
//});
const
runner
=
this
.
db
.
createQueryRunner
();
try
{
await
runner
.
connect
();
await
runner
.
startTransaction
();
await
runner
.
query
(
"
SET FOREIGN_KEY_CHECKS = 0;
"
);
await
runner
.
clearTable
(
"
duel_log_player
"
);
await
runner
.
clearTable
(
"
duel_log
"
);
await
runner
.
query
(
"
SET FOREIGN_KEY_CHECKS = 1;
"
);
await
runner
.
commitTransaction
();
}
catch
(
e
)
{
await
runner
.
rollbackTransaction
();
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
[])
{
const
duelLog
=
new
DuelLog
();
...
...
@@ -288,15 +305,17 @@ export class DataManager {
duelLog
.
roomMode
=
roomMode
;
duelLog
.
duelCount
=
duelCount
;
const
players
=
playerInfos
.
map
(
p
=>
DuelLogPlayer
.
fromDuelLogPlayerInfo
(
p
));
await
this
.
db
.
transaction
(
async
(
mdb
)
=>
{
await
this
.
transaction
(
async
(
mdb
)
=>
{
try
{
const
savedDuelLog
=
await
mdb
.
save
(
duelLog
);
for
(
let
player
of
players
)
{
player
.
duelLog
=
savedDuelLog
;
}
await
mdb
.
save
(
players
);
return
true
;
}
catch
(
e
)
{
this
.
log
.
warn
(
`Failed to save duel log
${
name
}
:
${
e
.
toString
()}
`
);
return
false
;
}
});
...
...
@@ -344,7 +363,7 @@ export class DataManager {
}
async
migrateChatColors
(
data
:
any
)
{
await
this
.
db
.
transaction
(
async
(
mdb
)
=>
{
await
this
.
transaction
(
async
(
mdb
)
=>
{
try
{
const
users
:
User
[]
=
[];
for
(
let
key
in
data
)
{
...
...
@@ -358,9 +377,10 @@ export class DataManager {
users
.
push
(
user
);
}
await
mdb
.
save
(
users
);
return
true
;
}
catch
(
e
)
{
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