[nextgen] fix memory leak, change default expiry to 5 minutes

This commit is contained in:
bignutty 2025-02-12 01:25:29 +01:00
parent 01a10135d8
commit fe8358ccf4
3 changed files with 12 additions and 12 deletions

View file

@ -1,7 +1,7 @@
const { createEmbed, page } = require("#utils/embed");
const { acknowledge } = require("#utils/interactions");
const DynamicCardStack = require("../../../labscore/cardstack/DynamicCardStack");
const { DynamicCardStack } = require("../../../labscore/cardstack/DynamicCardStack");
module.exports = {
label: "text",

View file

@ -7,7 +7,7 @@ const { acknowledge } = require('#utils/interactions');
const { smallPill, link, pill, stringwrapPreserveWords, timestamp, TIMESTAMP_FLAGS} = require('#utils/markdown');
const { editOrReply } = require('#utils/message');
const DynamicCardStack = require("../../../labscore/cardstack/DynamicCardStack");
const { DynamicCardStack } = require("../../../labscore/cardstack/DynamicCardStack");
const {STATIC_ASSETS} = require("#utils/statics");
function renderAnimeResultsPage(context, res){

View file

@ -1,13 +1,14 @@
const { createEmbed, page } = require("#utils/embed");
const { iconAsEmojiObject } = require("#utils/markdown");
const { editOrReply } = require("#utils/message");
const { STATIC_ASSETS } = require("#utils/statics");
const { Context } = require("detritus-client/lib/command");
const { MessageComponentTypes, InteractionCallbackTypes } = require("detritus-client/lib/constants");
const { Message } = require("detritus-client/lib/structures");
const { ComponentContext, Components, ComponentActionRow} = require("detritus-client/lib/utils");
const {createEmbed, page} = require("#utils/embed");
const {STATIC_ASSETS} = require("#utils/statics");
const activeStacks = new Map();
const activeStacks = new WeakMap();
const DEFAULT_BUTTON_ICON_MAPPINGS = Object.freeze({
"next": "button_chevron_right",
@ -51,7 +52,7 @@ class DynamicCardStack {
this.index = options.startingIndex || 0;
this.rootIndex = this.index;
this.loopPages = options.loop || true;
this.expires = options.expires || 1*60*1000;
this.expires = options.expires || 5*60*1000;
this.uniqueId = (Date.now()*Math.random()).toString(36);
@ -78,7 +79,7 @@ class DynamicCardStack {
if(clearComponents) await this._edit(this.currentPage(), [])
// Remove reference to free the cardstack for GC
activeStacks.delete(this.context.message?.id);
activeStacks.delete(this.context.message);
}
/**
@ -92,12 +93,12 @@ class DynamicCardStack {
_createDynamicCardStack(){
// Kill any previously active cardstacks
if(activeStacks.get(this.context.message?.id)){
if(activeStacks.get(this.context.message)){
console.log(this.uniqueId + " is replacing " + this._getStackByMessageId(this.context.message?.id).uniqueId);
this._getStackByMessageId(this.context.message?.id).kill();
this._getStackByMessageId(this.context.message).kill();
}
activeStacks.set(this.context.message?.id, this);
activeStacks.set(this.context.message, this);
}
_createTimeout(){
@ -364,7 +365,6 @@ class DynamicCardStack {
console.log("new category is " + this.currentSelectedSubcategory)
// TODO: allow overriding index
this.index = 0;
try{
@ -413,4 +413,4 @@ class DynamicCardStack {
}
}
module.exports = DynamicCardStack
module.exports.DynamicCardStack = DynamicCardStack;