Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Grasscutter
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
ziqian zhang
Grasscutter
Commits
f26fe213
Commit
f26fe213
authored
3 years ago
by
Bi Jiakai
Committed by
Melledy
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fixed account delete can not delete all related data (#767)
parent
fb3c3b71
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/emu/grasscutter/database/DatabaseHelper.java
+12
-7
12 additions, 7 deletions
src/main/java/emu/grasscutter/database/DatabaseHelper.java
with
12 additions
and
7 deletions
src/main/java/emu/grasscutter/database/DatabaseHelper.java
+
12
−
7
View file @
f26fe213
...
@@ -16,6 +16,8 @@ import emu.grasscutter.game.inventory.GameItem;
...
@@ -16,6 +16,8 @@ import emu.grasscutter.game.inventory.GameItem;
import
emu.grasscutter.game.mail.Mail
;
import
emu.grasscutter.game.mail.Mail
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.player.Player
;
import
static
com
.
mongodb
.
client
.
model
.
Filters
.
eq
;
public
final
class
DatabaseHelper
{
public
final
class
DatabaseHelper
{
public
static
Account
createAccount
(
String
username
)
{
public
static
Account
createAccount
(
String
username
)
{
return
createAccountWithId
(
username
,
0
);
return
createAccountWithId
(
username
,
0
);
...
@@ -101,17 +103,20 @@ public final class DatabaseHelper {
...
@@ -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
// 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 ...
// database in an inconsistent state, but unfortunately Mongo only supports that when we have a replica set ...
// Delete mails, gacha records, items and avatars.
// Delete Mail.class data
DatabaseManager
.
getDatastore
().
find
(
Mail
.
class
).
filter
(
Filters
.
eq
(
"ownerUid"
,
target
.
getPlayerUid
())).
delete
();
DatabaseManager
.
getDatabase
().
getCollection
(
"mail"
).
deleteMany
(
eq
(
"ownerUid"
,
target
.
getPlayerUid
()));
DatabaseManager
.
getDatastore
().
find
(
GachaRecord
.
class
).
filter
(
Filters
.
eq
(
"ownerId"
,
target
.
getPlayerUid
())).
delete
();
// Delete Avatar.class data
DatabaseManager
.
getDatastore
().
find
(
GameItem
.
class
).
filter
(
Filters
.
eq
(
"ownerId"
,
target
.
getPlayerUid
())).
delete
();
DatabaseManager
.
getDatabase
().
getCollection
(
"avatars"
).
deleteMany
(
eq
(
"ownerId"
,
target
.
getPlayerUid
()));
DatabaseManager
.
getDatastore
().
find
(
Avatar
.
class
).
filter
(
Filters
.
eq
(
"ownerId"
,
target
.
getPlayerUid
())).
delete
();
// 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.
// Delete friendships.
// Here, we need to make sure to not only delete the deleted account's 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.
// 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
base
().
getCollection
(
"friendships"
).
deleteMany
(
eq
(
"ownerId"
,
target
.
getPlayerUid
()));
DatabaseManager
.
getData
store
().
find
(
Friendship
.
class
).
filter
(
Filters
.
eq
(
"friendId"
,
target
.
getPlayerUid
()))
.
delete
()
;
DatabaseManager
.
getData
base
().
getCollection
(
"friendships"
).
deleteMany
(
eq
(
"friendId"
,
target
.
getPlayerUid
()));
// Delete the player.
// Delete the player.
DatabaseManager
.
getDatastore
().
find
(
Player
.
class
).
filter
(
Filters
.
eq
(
"id"
,
target
.
getPlayerUid
())).
delete
();
DatabaseManager
.
getDatastore
().
find
(
Player
.
class
).
filter
(
Filters
.
eq
(
"id"
,
target
.
getPlayerUid
())).
delete
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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