From f1f583a13baa7c028b2254f5f3d27243909e6712 Mon Sep 17 00:00:00 2001 From: Ivan Liang Date: Fri, 25 Oct 2024 11:28:38 -0400 Subject: [PATCH] Simplify TTL mechanism Now we bypass aframe data lifecycle, we directly push new expireAt times from create_update, avoiding issue with updates not happening properly based on values and when tabbed out with no RAF Resolves #668 --- src/components/object/ttl.js | 10 ++-------- src/systems/core/message-actions/create-update.js | 9 +++------ 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/components/object/ttl.js b/src/components/object/ttl.js index d7c7a3da3..aa8cd1fa5 100644 --- a/src/components/object/ttl.js +++ b/src/components/object/ttl.js @@ -23,16 +23,10 @@ AFRAME.registerComponent('ttl', { expireAt: { type: 'int' }, }, init() { - console.log('ttl', 'init', this.data.expireAt, this.el.id); - if (this.data.expireAt > 0) { - this.expireAt = Date.now() + this.data.seconds * 1000; - this.tick = AFRAME.utils.throttleTick(this.tick, 1000, this); - } + this.tick = AFRAME.utils.throttleTick(this.tick, 1000, this); }, tick() { - const now = Date.now(); - if (this.data.expireAt > 0 && now > this.data.expireAt) { - console.log('ttl', 'delete', this.data.expireAt, this.el.id); + if (Date.now() > this.data.expireAt) { Delete.handle({ id: this.el.id }); } }, diff --git a/src/systems/core/message-actions/create-update.js b/src/systems/core/message-actions/create-update.js index acdfb5e7c..d89aaeb6e 100644 --- a/src/systems/core/message-actions/create-update.js +++ b/src/systems/core/message-actions/create-update.js @@ -135,12 +135,9 @@ export default class CreateUpdate { } } - if (message.ttl !== undefined) { - console.log('ttl', 'message', message.ttl, id); - if (message.ttl >= 0) { - // Allow -1 to bypass TTL update, retains previous timeout - entityEl.setAttribute('ttl', { expireAt: Date.now() + message.ttl * 1000 }); - } + if (message.ttl !== undefined && message.ttl >= 0) { + // Allow -1 to bypass TTL update, retains previous timeout + entityEl.setAttribute('ttl', { expireAt: Date.now() + message.ttl * 1000 }); } // Private and program_id flags. Falsy values unset (undefined, null, 0, '')