Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
f26fe213
Commit
f26fe213
authored
May 10, 2022
by
Bi Jiakai
Committed by
Melledy
May 10, 2022
Browse files
Fixed account delete can not delete all related data (#767)
parent
fb3c3b71
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/database/DatabaseHelper.java
View file @
f26fe213
...
...
@@ -16,6 +16,8 @@ import emu.grasscutter.game.inventory.GameItem;
import
emu.grasscutter.game.mail.Mail
;
import
emu.grasscutter.game.player.Player
;
import
static
com
.
mongodb
.
client
.
model
.
Filters
.
eq
;
public
final
class
DatabaseHelper
{
public
static
Account
createAccount
(
String
username
)
{
return
createAccountWithId
(
username
,
0
);
...
...
@@ -101,17 +103,20 @@ public final class DatabaseHelper {
// This should optimally be wrapped inside a transaction, to make sure an error thrown mid-way does not leave the
// database in an inconsistent state, but unfortunately Mongo only supports that when we have a replica set ...
// Delete mails, gacha records, items and avatars.
DatabaseManager
.
getDatastore
().
find
(
Mail
.
class
).
filter
(
Filters
.
eq
(
"ownerUid"
,
target
.
getPlayerUid
())).
delete
();
DatabaseManager
.
getDatastore
().
find
(
GachaRecord
.
class
).
filter
(
Filters
.
eq
(
"ownerId"
,
target
.
getPlayerUid
())).
delete
();
DatabaseManager
.
getDatastore
().
find
(
GameItem
.
class
).
filter
(
Filters
.
eq
(
"ownerId"
,
target
.
getPlayerUid
())).
delete
();
DatabaseManager
.
getDatastore
().
find
(
Avatar
.
class
).
filter
(
Filters
.
eq
(
"ownerId"
,
target
.
getPlayerUid
())).
delete
();
// Delete Mail.class data
DatabaseManager
.
getDatabase
().
getCollection
(
"mail"
).
deleteMany
(
eq
(
"ownerUid"
,
target
.
getPlayerUid
()));
// Delete Avatar.class data
DatabaseManager
.
getDatabase
().
getCollection
(
"avatars"
).
deleteMany
(
eq
(
"ownerId"
,
target
.
getPlayerUid
()));
// Delete GachaRecord.class data
DatabaseManager
.
getDatabase
().
getCollection
(
"gachas"
).
deleteMany
(
eq
(
"ownerId"
,
target
.
getPlayerUid
()));
// Delete GameItem.class data
DatabaseManager
.
getDatabase
().
getCollection
(
"items"
).
deleteMany
(
eq
(
"ownerId"
,
target
.
getPlayerUid
()));
// Delete friendships.
// Here, we need to make sure to not only delete the deleted account's friendships,
// but also all friendship entries for that account's friends.
DatabaseManager
.
getData
store
().
find
(
Friendship
.
class
).
filter
(
Filters
.
eq
(
"ownerId"
,
target
.
getPlayerUid
()))
.
delete
()
;
DatabaseManager
.
getData
store
().
find
(
Friendship
.
class
).
filter
(
Filters
.
eq
(
"friendId"
,
target
.
getPlayerUid
()))
.
delete
()
;
DatabaseManager
.
getData
base
().
getCollection
(
"friendships"
).
deleteMany
(
eq
(
"ownerId"
,
target
.
getPlayerUid
()));
DatabaseManager
.
getData
base
().
getCollection
(
"friendships"
).
deleteMany
(
eq
(
"friendId"
,
target
.
getPlayerUid
()));
// Delete the player.
DatabaseManager
.
getDatastore
().
find
(
Player
.
class
).
filter
(
Filters
.
eq
(
"id"
,
target
.
getPlayerUid
())).
delete
();
...
...
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