Skip to content

Commit

Permalink
Simplify TTL mechanism
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hi-liang committed Oct 25, 2024
1 parent dc5430a commit f1f583a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
10 changes: 2 additions & 8 deletions src/components/object/ttl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
},
Expand Down
9 changes: 3 additions & 6 deletions src/systems/core/message-actions/create-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '')
Expand Down

0 comments on commit f1f583a

Please sign in to comment.