mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 06:03:04 -04:00
[nextgen] fix memory leak, change default expiry to 5 minutes
This commit is contained in:
parent
01a10135d8
commit
fe8358ccf4
3 changed files with 12 additions and 12 deletions
|
@ -1,7 +1,7 @@
|
||||||
const { createEmbed, page } = require("#utils/embed");
|
const { createEmbed, page } = require("#utils/embed");
|
||||||
const { acknowledge } = require("#utils/interactions");
|
const { acknowledge } = require("#utils/interactions");
|
||||||
|
|
||||||
const DynamicCardStack = require("../../../labscore/cardstack/DynamicCardStack");
|
const { DynamicCardStack } = require("../../../labscore/cardstack/DynamicCardStack");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
label: "text",
|
label: "text",
|
||||||
|
|
|
@ -7,7 +7,7 @@ const { acknowledge } = require('#utils/interactions');
|
||||||
const { smallPill, link, pill, stringwrapPreserveWords, timestamp, TIMESTAMP_FLAGS} = require('#utils/markdown');
|
const { smallPill, link, pill, stringwrapPreserveWords, timestamp, TIMESTAMP_FLAGS} = require('#utils/markdown');
|
||||||
const { editOrReply } = require('#utils/message');
|
const { editOrReply } = require('#utils/message');
|
||||||
|
|
||||||
const DynamicCardStack = require("../../../labscore/cardstack/DynamicCardStack");
|
const { DynamicCardStack } = require("../../../labscore/cardstack/DynamicCardStack");
|
||||||
const {STATIC_ASSETS} = require("#utils/statics");
|
const {STATIC_ASSETS} = require("#utils/statics");
|
||||||
|
|
||||||
function renderAnimeResultsPage(context, res){
|
function renderAnimeResultsPage(context, res){
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
|
const { createEmbed, page } = require("#utils/embed");
|
||||||
const { iconAsEmojiObject } = require("#utils/markdown");
|
const { iconAsEmojiObject } = require("#utils/markdown");
|
||||||
const { editOrReply } = require("#utils/message");
|
const { editOrReply } = require("#utils/message");
|
||||||
|
const { STATIC_ASSETS } = require("#utils/statics");
|
||||||
|
|
||||||
const { Context } = require("detritus-client/lib/command");
|
const { Context } = require("detritus-client/lib/command");
|
||||||
const { MessageComponentTypes, InteractionCallbackTypes } = require("detritus-client/lib/constants");
|
const { MessageComponentTypes, InteractionCallbackTypes } = require("detritus-client/lib/constants");
|
||||||
const { Message } = require("detritus-client/lib/structures");
|
const { Message } = require("detritus-client/lib/structures");
|
||||||
const { ComponentContext, Components, ComponentActionRow} = require("detritus-client/lib/utils");
|
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({
|
const DEFAULT_BUTTON_ICON_MAPPINGS = Object.freeze({
|
||||||
"next": "button_chevron_right",
|
"next": "button_chevron_right",
|
||||||
|
@ -51,7 +52,7 @@ class DynamicCardStack {
|
||||||
this.index = options.startingIndex || 0;
|
this.index = options.startingIndex || 0;
|
||||||
this.rootIndex = this.index;
|
this.rootIndex = this.index;
|
||||||
this.loopPages = options.loop || true;
|
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);
|
this.uniqueId = (Date.now()*Math.random()).toString(36);
|
||||||
|
|
||||||
|
@ -78,7 +79,7 @@ class DynamicCardStack {
|
||||||
if(clearComponents) await this._edit(this.currentPage(), [])
|
if(clearComponents) await this._edit(this.currentPage(), [])
|
||||||
|
|
||||||
// Remove reference to free the cardstack for GC
|
// 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(){
|
_createDynamicCardStack(){
|
||||||
// Kill any previously active cardstacks
|
// 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);
|
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(){
|
_createTimeout(){
|
||||||
|
@ -364,7 +365,6 @@ class DynamicCardStack {
|
||||||
|
|
||||||
console.log("new category is " + this.currentSelectedSubcategory)
|
console.log("new category is " + this.currentSelectedSubcategory)
|
||||||
|
|
||||||
// TODO: allow overriding index
|
|
||||||
this.index = 0;
|
this.index = 0;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
@ -413,4 +413,4 @@ class DynamicCardStack {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = DynamicCardStack
|
module.exports.DynamicCardStack = DynamicCardStack;
|
Loading…
Add table
Add a link
Reference in a new issue