Merge pull request #897 from shocknet/activate-users-cleanup

clean users table
This commit is contained in:
Justin (shocknet) 2026-03-02 15:05:45 -05:00 committed by GitHub
commit a0b77ec1ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 5 deletions

View file

@ -176,6 +176,11 @@ export default class {
this.log("Deleting", toDelete.length, "inactive users")
for (let i = 0; i < toDelete.length; 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)
await this.storage.StartTransaction(async tx => {
for (const appUserId of appUserIds) {
@ -183,11 +188,12 @@ export default class {
await this.storage.offerStorage.DeleteUserOffers(appUserId, tx)
await this.storage.debitStorage.RemoveUserDebitAccess(appUserId, tx)
await this.storage.applicationStorage.RemoveAppUserDevices(appUserId, tx)
}
await this.storage.paymentStorage.RemoveUserInvoices(userId, tx)
await this.storage.productStorage.RemoveUserProducts(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")

View file

@ -161,10 +161,16 @@ export default class {
this.dbs.Remove<User>('User', baseUser, txId)
}
async RemoveAppUsersAndBaseUsers(appUserIds: string[],baseUser:string, txId?: string) {
await this.dbs.Delete<ApplicationUser>('ApplicationUser', { identifier: In(appUserIds) }, txId)
await this.dbs.Delete<User>('User', { user_id: baseUser }, txId)
async RemoveAppUsersAndBaseUsers(appUserIds: string[], baseUser: string, txId?: string) {
if (appUserIds.length > 0) {
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)
}

View file

@ -126,4 +126,8 @@ export default class {
const lastSeenAtUnix = now - seconds
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)
}
}