all repos — underbbs @ b4145db3597f7971c9fdf851317ec3536e0ee806

decentralized social media client

fix batch timer and use it for authors
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQT/foVVmI9pK13hPWFohAcXSWbK8wUCZsD6bQAKCRBohAcXSWbK
8+yKAPwLT1q75Rh2HXKgsWGxrre5Tl7Tra1bKLvPJPtAmAO/gQD/fUd2EK/t6CyX
12dUx+LiY3HaPxoUv8WyVL1x7xSEPA8=
=RgSs
-----END PGP SIGNATURE-----
commit

b4145db3597f7971c9fdf851317ec3536e0ee806

parent

bcfe1587c944b2faecec4b961f6ff91581181279

2 files changed, 12 insertions(+), 5 deletions(-)

jump to
M frontend/ts/batch-timer.tsfrontend/ts/batch-timer.ts

@@ -12,7 +12,7 @@

public queue(id: string, timeout: number){ this._timer = new Date().getTime() + timeout; this._batch.push(id); - setTimeout(this.checkBatch, timeout); + setTimeout(this.checkBatch.bind(this), timeout); } private checkBatch() {
M frontend/ts/thread-summary-element.tsfrontend/ts/thread-summary-element.ts

@@ -1,6 +1,7 @@

import util from "./util" import { Message, Author } from "./message" import { AdapterState } from "./adapter" +import { BatchTimer } from "./batch-timer" export class ThreadSummaryElement extends HTMLElement { static observedAttributes = [ "data-msg", "data-len", "data-author", "data-created", "data-latest", "data-new" ];

@@ -13,6 +14,8 @@ private _created: number = 0;

private _latest: number = 0; private _new: boolean = false; + private _authorTimer: BatchTimer; + constructor() { super(); this.innerHTML = "<div class='thread_summary'><div class='thread_author'></div><div class='thread_text'></div><div class='thread_metadata'></div></div>"

@@ -20,6 +23,13 @@

// adapter shouldn't change, just set it here this._adapter = this.getAttribute("data-adapter") ?? ""; this.addEventListener("click", this.viewThread(this), false); + this._authorTimer = new BatchTimer((ids: string[])=>{ + let url = `/api/adapters/${this._adapter}/fetch?entity_type=author`; + for (let id of ids) { + url += `&entity_id=${id}`; + } + util.authorizedFetch("GET", url, null) + }); } connectedCallback() {

@@ -54,10 +64,7 @@ case "data-author":

if (next) { let authorData= datastore.profileCache.get(next); if (!authorData) { - util.authorizedFetch( - "GET", - `/api/adapters/${this._adapter}/fetch?entity_type=author&entity_id=${next}`, - null); + this._authorTimer.queue(next, 2000); this._author = <Author>{id: next}; const threadAuthor = this.querySelector(".thread_author"); if (threadAuthor) {