Merge pull request #897 from shocknet/activate-users-cleanup
clean users table
This commit is contained in:
commit
a0b77ec1ca
3 changed files with 21 additions and 5 deletions
|
|
@ -176,6 +176,11 @@ export default class {
|
||||||
this.log("Deleting", toDelete.length, "inactive users")
|
this.log("Deleting", toDelete.length, "inactive users")
|
||||||
for (let i = 0; i < toDelete.length; i++) {
|
for (let i = 0; i < toDelete.length; i++) {
|
||||||
const { userId, appUserIds } = toDelete[i]
|
const { userId, appUserIds } = toDelete[i]
|
||||||
|
const user = await this.storage.userStorage.FindUser(userId)
|
||||||
|
if (!user || user.balance_sats > 0) {
|
||||||
|
if (user) this.log("Skipping user", userId, "has balance", user.balance_sats)
|
||||||
|
continue
|
||||||
|
}
|
||||||
this.log("Deleting user", userId, "progress", i + 1, "/", toDelete.length)
|
this.log("Deleting user", userId, "progress", i + 1, "/", toDelete.length)
|
||||||
await this.storage.StartTransaction(async tx => {
|
await this.storage.StartTransaction(async tx => {
|
||||||
for (const appUserId of appUserIds) {
|
for (const appUserId of appUserIds) {
|
||||||
|
|
@ -183,11 +188,12 @@ export default class {
|
||||||
await this.storage.offerStorage.DeleteUserOffers(appUserId, tx)
|
await this.storage.offerStorage.DeleteUserOffers(appUserId, tx)
|
||||||
await this.storage.debitStorage.RemoveUserDebitAccess(appUserId, tx)
|
await this.storage.debitStorage.RemoveUserDebitAccess(appUserId, tx)
|
||||||
await this.storage.applicationStorage.RemoveAppUserDevices(appUserId, tx)
|
await this.storage.applicationStorage.RemoveAppUserDevices(appUserId, tx)
|
||||||
|
|
||||||
}
|
}
|
||||||
await this.storage.paymentStorage.RemoveUserInvoices(userId, tx)
|
await this.storage.paymentStorage.RemoveUserInvoices(userId, tx)
|
||||||
await this.storage.productStorage.RemoveUserProducts(userId, tx)
|
await this.storage.productStorage.RemoveUserProducts(userId, tx)
|
||||||
await this.storage.paymentStorage.RemoveUserEphemeralKeys(userId, tx)
|
await this.storage.paymentStorage.RemoveUserEphemeralKeys(userId, tx)
|
||||||
|
await this.storage.userStorage.DeleteUserAccess(userId, tx)
|
||||||
|
await this.storage.applicationStorage.RemoveAppUsersAndBaseUsers(appUserIds, userId, tx)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.log("Cleaned up inactive users")
|
this.log("Cleaned up inactive users")
|
||||||
|
|
|
||||||
|
|
@ -162,9 +162,15 @@ export default class {
|
||||||
}
|
}
|
||||||
|
|
||||||
async RemoveAppUsersAndBaseUsers(appUserIds: string[], baseUser: string, txId?: string) {
|
async RemoveAppUsersAndBaseUsers(appUserIds: string[], baseUser: string, txId?: string) {
|
||||||
await this.dbs.Delete<ApplicationUser>('ApplicationUser', { identifier: In(appUserIds) }, txId)
|
if (appUserIds.length > 0) {
|
||||||
await this.dbs.Delete<User>('User', { user_id: baseUser }, txId)
|
const appUsers = await this.dbs.Find<ApplicationUser>('ApplicationUser', { where: { identifier: In(appUserIds) } }, txId)
|
||||||
|
for (const appUser of appUsers) {
|
||||||
|
await this.dbs.Delete<ApplicationUser>('ApplicationUser', appUser.serial_id, txId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const user = await this.userStorage.FindUser(baseUser, txId)
|
||||||
|
if (!user) return
|
||||||
|
await this.dbs.Delete<User>('User', user.serial_id, txId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -126,4 +126,8 @@ export default class {
|
||||||
const lastSeenAtUnix = now - seconds
|
const lastSeenAtUnix = now - seconds
|
||||||
return this.dbs.Find<UserAccess>('UserAccess', { where: { last_seen_at_unix: LessThan(lastSeenAtUnix) } })
|
return this.dbs.Find<UserAccess>('UserAccess', { where: { last_seen_at_unix: LessThan(lastSeenAtUnix) } })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async DeleteUserAccess(userId: string, txId?: string) {
|
||||||
|
return this.dbs.Delete<UserAccess>('UserAccess', { user_id: userId }, txId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue