old with small balance + old invoices
This commit is contained in:
parent
517d08408c
commit
3ae9dccf02
4 changed files with 33 additions and 4 deletions
|
|
@ -123,6 +123,23 @@ export default class {
|
|||
|
||||
async CleanupInactiveUsers() {
|
||||
this.log("Cleaning up inactive users")
|
||||
const inactiveUsers = await this.storage.userStorage.GetInactiveUsers(365)
|
||||
const toDelete:{userId: string, appUserIds: string[]}[] = []
|
||||
for (const u of inactiveUsers) {
|
||||
const user = await this.storage.userStorage.GetUser(u.user_id)
|
||||
if (user.balance_sats > 10_000) {
|
||||
continue
|
||||
}
|
||||
const appUsers = await this.storage.applicationStorage.GetAllAppUsersFromUser(u.user_id)
|
||||
toDelete.push({userId: u.user_id, appUserIds: appUsers.map(a => a.identifier)})
|
||||
}
|
||||
|
||||
this.log("Found",toDelete.length, "inactive users to delete")
|
||||
// await this.RemoveUsers(toDelete)
|
||||
}
|
||||
|
||||
async CleanupNeverActiveUsers() {
|
||||
this.log("Cleaning up never active users")
|
||||
const inactiveUsers = await this.storage.userStorage.GetInactiveUsers(30)
|
||||
const toDelete:{userId: string, appUserIds: string[]}[] = []
|
||||
for (const u of inactiveUsers) {
|
||||
|
|
@ -146,11 +163,11 @@ export default class {
|
|||
toDelete.push({userId: u.user_id, appUserIds: appUsers.map(a => a.identifier)})
|
||||
}
|
||||
|
||||
this.log("Found",toDelete.length, "inactive users to delete")
|
||||
// await this.RemoveIntactiveUsers(toDelete) TODO: activate deletion
|
||||
this.log("Found",toDelete.length, "never active users to delete")
|
||||
// await this.RemoveUsers(toDelete) TODO: activate deletion
|
||||
}
|
||||
|
||||
async RemoveIntactiveUsers(toDelete: { userId: string, appUserIds: string[] }[]) {
|
||||
async RemoveUsers(toDelete: { userId: string, appUserIds: string[] }[]) {
|
||||
this.log("Deleting",toDelete.length, "inactive users")
|
||||
for (let i = 0; i < toDelete.length; i++) {
|
||||
const {userId,appUserIds} = toDelete[i]
|
||||
|
|
|
|||
|
|
@ -75,7 +75,9 @@ export const initMainHandler = async (log: PubLogger, mainSettings: MainSettings
|
|||
return
|
||||
}
|
||||
await mainHandler.paymentManager.checkPendingPayments()
|
||||
await mainHandler.paymentManager.CleanupOldUnpaidInvoices()
|
||||
await mainHandler.appUserManager.CleanupInactiveUsers()
|
||||
await mainHandler.appUserManager.CleanupNeverActiveUsers()
|
||||
await mainHandler.paymentManager.watchDog.Start()
|
||||
return { mainHandler, apps, liquidityProviderInfo, liquidityProviderApp, wizard, adminManager }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -759,6 +759,12 @@ export default class {
|
|||
return newlyConfirmedTxs.filter(t => t !== undefined) as (PendingTx & { confs: number })[]
|
||||
}
|
||||
|
||||
async CleanupOldUnpaidInvoices() {
|
||||
this.log("Cleaning up old unpaid invoices")
|
||||
const affected = await this.storage.paymentStorage.RemoveOldUnpaidInvoices()
|
||||
this.log("Cleaned up",affected, "old unpaid invoices")
|
||||
}
|
||||
|
||||
async GetLndBalance() {
|
||||
return this.lnd.GetBalance()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import crypto from 'crypto';
|
||||
import { And, Between, Equal, FindOperator, IsNull, LessThanOrEqual, MoreThan, MoreThanOrEqual } from "typeorm"
|
||||
import { And, Between, Equal, FindOperator, IsNull, LessThan, LessThanOrEqual, MoreThan, MoreThanOrEqual } from "typeorm"
|
||||
import { User } from './entity/User.js';
|
||||
import { UserTransactionPayment } from './entity/UserTransactionPayment.js';
|
||||
import { EphemeralKeyType, UserEphemeralKey } from './entity/UserEphemeralKey.js';
|
||||
|
|
@ -111,6 +111,10 @@ export default class {
|
|||
return items
|
||||
}
|
||||
|
||||
async RemoveOldUnpaidInvoices(txId?: string) {
|
||||
return this.dbs.Delete<UserReceivingInvoice>('UserReceivingInvoice', { paid_at_unix: 0, expires_at_unix: LessThan(Math.floor(Date.now() / 1000)) }, txId)
|
||||
}
|
||||
|
||||
async AddUserInvoice(user: User, invoice: string, options: InboundOptionals = { expiry: defaultInvoiceExpiry }, providerDestination?: string, txId?: string): Promise<UserReceivingInvoice> {
|
||||
return this.dbs.CreateAndSave<UserReceivingInvoice>('UserReceivingInvoice', {
|
||||
invoice: invoice,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue