bug: feed loading
This commit is contained in:
parent
6219626ba0
commit
46fc4500d7
@ -1,12 +1,14 @@
|
||||
import { useEffect } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import Timeline from "Element/Timeline";
|
||||
import { TaskList } from "Tasks/TaskList";
|
||||
import useLogin from "Hooks/useLogin";
|
||||
import { markNotificationsRead } from "Login";
|
||||
import { unixNow } from "Util";
|
||||
|
||||
export default function NotificationsPage() {
|
||||
const login = useLogin();
|
||||
const [now] = useState(unixNow());
|
||||
|
||||
useEffect(() => {
|
||||
markNotificationsRead(login);
|
||||
@ -24,6 +26,8 @@ export default function NotificationsPage() {
|
||||
items: [login.publicKey],
|
||||
discriminator: login.publicKey.slice(0, 12),
|
||||
}}
|
||||
now={now}
|
||||
window={60 * 60 * 12}
|
||||
postsOnly={false}
|
||||
method={"TIME_RANGE"}
|
||||
/>
|
||||
|
@ -65,19 +65,23 @@ class ProfileLoaderService {
|
||||
|
||||
const q = System.Query<PubkeyReplaceableNoteStore>(PubkeyReplaceableNoteStore, sub);
|
||||
// never release this callback, it will stop firing anyway after eose
|
||||
const releaseOnEvent = q.onEvent(e => this.onProfileEvent(e));
|
||||
const releaseOnEvent = q.onEvent(async e => {
|
||||
await this.onProfileEvent(e);
|
||||
});
|
||||
const results = await new Promise<Readonly<Array<TaggedRawEvent>>>(resolve => {
|
||||
let timeout: ReturnType<typeof setTimeout> | undefined = undefined;
|
||||
const release = q.hook(() => {
|
||||
if (!q.loading) {
|
||||
clearTimeout(timeout);
|
||||
resolve(q.getSnapshotData() ?? []);
|
||||
console.debug("Profiles finished: ", sub.id);
|
||||
release();
|
||||
}
|
||||
release();
|
||||
});
|
||||
timeout = setTimeout(() => {
|
||||
release();
|
||||
resolve(q.getSnapshotData() ?? []);
|
||||
console.debug("Profiles timeout: ", sub.id);
|
||||
}, 5_000);
|
||||
});
|
||||
|
||||
|
@ -1,18 +1,23 @@
|
||||
import { Connection } from "@snort/nostr";
|
||||
import { Query } from "./Query";
|
||||
import { getRandomValues } from "crypto";
|
||||
import { FlatNoteStore } from "./NoteCollection";
|
||||
|
||||
window.crypto = {} as any;
|
||||
window.crypto.getRandomValues = getRandomValues as any;
|
||||
|
||||
describe("query", () => {
|
||||
test("progress", () => {
|
||||
const q = new Query("test", [
|
||||
{
|
||||
kinds: [1],
|
||||
authors: ["test"],
|
||||
},
|
||||
]);
|
||||
const q = new Query(
|
||||
"test",
|
||||
[
|
||||
{
|
||||
kinds: [1],
|
||||
authors: ["test"],
|
||||
},
|
||||
],
|
||||
new FlatNoteStore()
|
||||
);
|
||||
const opt = {
|
||||
read: true,
|
||||
write: true,
|
||||
@ -38,12 +43,16 @@ describe("query", () => {
|
||||
q.eose(q.id, c3);
|
||||
expect(q.progress).toBe(1);
|
||||
|
||||
const qs = new Query("test-1", [
|
||||
{
|
||||
kinds: [1],
|
||||
authors: ["test-sub"],
|
||||
},
|
||||
]);
|
||||
const qs = new Query(
|
||||
"test-1",
|
||||
[
|
||||
{
|
||||
kinds: [1],
|
||||
authors: ["test-sub"],
|
||||
},
|
||||
],
|
||||
new FlatNoteStore()
|
||||
);
|
||||
q.subQueries.push(qs);
|
||||
qs.sendToRelay(c1);
|
||||
|
||||
|
@ -121,9 +121,9 @@ export class Query {
|
||||
/**
|
||||
* Feed object which collects events
|
||||
*/
|
||||
#feed?: NoteStore;
|
||||
#feed: NoteStore;
|
||||
|
||||
constructor(id: string, filters: Array<RawReqFilter>, feed?: NoteStore) {
|
||||
constructor(id: string, filters: Array<RawReqFilter>, feed: NoteStore) {
|
||||
this.id = id;
|
||||
this.filters = filters;
|
||||
this.#feed = feed;
|
||||
@ -190,14 +190,12 @@ export class Query {
|
||||
}
|
||||
|
||||
eose(sub: string, conn: Readonly<Connection>) {
|
||||
const qt = this.#tracing.filter(a => a.subId === sub && a.connId === conn.Id);
|
||||
const qt = this.#tracing.find(a => a.subId === sub && a.connId === conn.Id);
|
||||
qt?.gotEose();
|
||||
if (sub === this.id) {
|
||||
console.debug(`[EOSE][${sub}] ${conn.Address}`);
|
||||
qt.forEach(a => a.gotEose());
|
||||
if (this.#feed) {
|
||||
this.#feed.loading = this.progress < 1;
|
||||
}
|
||||
if (!this.leaveOpen) {
|
||||
this.#feed.loading = this.progress < 1;
|
||||
if (!this.leaveOpen && !this.#feed.loading) {
|
||||
this.sendClose();
|
||||
}
|
||||
} else {
|
||||
|
@ -212,14 +212,13 @@ export class NostrSystem {
|
||||
this.#changed();
|
||||
return unwrap(q.feed) as Readonly<T>;
|
||||
} else {
|
||||
const subQ = new Query(`${q.id}-${q.subQueries.length + 1}`, filters);
|
||||
const subQ = new Query(`${q.id}-${q.subQueries.length + 1}`, filters, q.feed);
|
||||
q.subQueries.push(subQ);
|
||||
q.filters = filters;
|
||||
const f = unwrap(q.feed);
|
||||
f.loading = true;
|
||||
q.feed.loading = true;
|
||||
this.SendQuery(subQ);
|
||||
this.#changed();
|
||||
return f as Readonly<T>;
|
||||
return q.feed as Readonly<T>;
|
||||
}
|
||||
} else {
|
||||
return this.AddQuery<T>(type, req);
|
||||
|
Loading…
x
Reference in New Issue
Block a user