fix batch timer and use it for authors
This commit is contained in:
parent
bcfe1587c9
commit
b4145db359
2 changed files with 12 additions and 5 deletions
|
@ -12,7 +12,7 @@ export class BatchTimer {
|
||||||
public queue(id: string, timeout: number){
|
public queue(id: string, timeout: number){
|
||||||
this._timer = new Date().getTime() + timeout;
|
this._timer = new Date().getTime() + timeout;
|
||||||
this._batch.push(id);
|
this._batch.push(id);
|
||||||
setTimeout(this.checkBatch, timeout);
|
setTimeout(this.checkBatch.bind(this), timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
private checkBatch() {
|
private checkBatch() {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import util from "./util"
|
import util from "./util"
|
||||||
import { Message, Author } from "./message"
|
import { Message, Author } from "./message"
|
||||||
import { AdapterState } from "./adapter"
|
import { AdapterState } from "./adapter"
|
||||||
|
import { BatchTimer } from "./batch-timer"
|
||||||
|
|
||||||
export class ThreadSummaryElement extends HTMLElement {
|
export class ThreadSummaryElement extends HTMLElement {
|
||||||
static observedAttributes = [ "data-msg", "data-len", "data-author", "data-created", "data-latest", "data-new" ];
|
static observedAttributes = [ "data-msg", "data-len", "data-author", "data-created", "data-latest", "data-new" ];
|
||||||
|
@ -13,6 +14,8 @@ export class ThreadSummaryElement extends HTMLElement {
|
||||||
private _latest: number = 0;
|
private _latest: number = 0;
|
||||||
private _new: boolean = false;
|
private _new: boolean = false;
|
||||||
|
|
||||||
|
private _authorTimer: BatchTimer;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.innerHTML = "<div class='thread_summary'><div class='thread_author'></div><div class='thread_text'></div><div class='thread_metadata'></div></div>"
|
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 @@ export class ThreadSummaryElement extends HTMLElement {
|
||||||
// adapter shouldn't change, just set it here
|
// adapter shouldn't change, just set it here
|
||||||
this._adapter = this.getAttribute("data-adapter") ?? "";
|
this._adapter = this.getAttribute("data-adapter") ?? "";
|
||||||
this.addEventListener("click", this.viewThread(this), false);
|
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() {
|
connectedCallback() {
|
||||||
|
@ -54,10 +64,7 @@ export class ThreadSummaryElement extends HTMLElement {
|
||||||
if (next) {
|
if (next) {
|
||||||
let authorData= datastore.profileCache.get(next);
|
let authorData= datastore.profileCache.get(next);
|
||||||
if (!authorData) {
|
if (!authorData) {
|
||||||
util.authorizedFetch(
|
this._authorTimer.queue(next, 2000);
|
||||||
"GET",
|
|
||||||
`/api/adapters/${this._adapter}/fetch?entity_type=author&entity_id=${next}`,
|
|
||||||
null);
|
|
||||||
this._author = <Author>{id: next};
|
this._author = <Author>{id: next};
|
||||||
const threadAuthor = this.querySelector(".thread_author");
|
const threadAuthor = this.querySelector(".thread_author");
|
||||||
if (threadAuthor) {
|
if (threadAuthor) {
|
||||||
|
|
Loading…
Reference in a new issue