Smarter loading.

This changes to always on explore (though this may change yet again).
This is so we always get new events and we simply filter out who we want
to see. This also replaces the recent history.

I also changed contacts to check if we have contacts from storage and if
not to fetch them. This solves login loading issues.

There are still issues (IMO) with profile loading and thread loading
that need investigation. Profile loading just seems slow and threads
seems to not have posts. I think this may be because the relay is not
sending them to me because it's busy with the explore subscription. The
other relays seem fine, but Damus relay seems slow or unresponsive as I
will send a REQ and it will go completely unanswered, yet return explore
events.
This commit is contained in:
Thomas Mathews 2022-12-27 10:24:32 -08:00
parent 9fa6974914
commit 1847b64855
3 changed files with 31 additions and 35 deletions

View file

@ -161,18 +161,18 @@ function on_pool_open(relay) {
limit: 5000,
}]);
/*// Get the latest history as a prefetch
relay.subscribe(SID_HISTORY, [{
// Subscribe to the world as it will serve our friends, notifications, and
// explore views
relay.subscribe(SID_EXPLORE, [{
kinds: STANDARD_KINDS,
limit: 500,
}]);*/
// Grab our friends history so our default timeline looks loaded
relay.subscribe(SID_FRIENDS, [{
kinds: STANDARD_KINDS,
authors: Array.from(model.contacts.friends),
limit: 500,
}]);
// Grab our friends history so our default timeline looks loaded
if (model.contacts.friends.size > 0) {
model_get_relay_que(model, relay).contacts_init = true;
fetch_friends_history(Array.from(model.contacts.friends), model.pool, relay);
}
}
function on_pool_notice(relay, notice) {
@ -188,15 +188,24 @@ async function on_pool_eose(relay, sub_id) {
const index = sub_id.indexOf(":");
const sid = sub_id.slice(0, index >= 0 ? index : sub_id.length);
const identifier = sub_id.slice(index+1);
switch (sid) {
case SID_HISTORY:
case SID_THREAD:
case SID_FRIENDS:
view_timeline_refresh(model);
pool.unsubscribe(sub_id, relay);
break
case SID_FRIENDS:
view_timeline_refresh(model);
case SID_META:
// if sid is ours and we did not init properly (must be login) then
// we will fetch our friends history now
if (model.pubkey == identifier &&
!model_get_relay_que(model, relay).contacts_init) {
fetch_friends_history(Array.from(model.contacts.friends),
pool, relay);
log_debug("Got our friends after no init & fetching our friends");
}
case SID_NOTIFICATIONS:
case SID_PROFILES:
pool.unsubscribe(sub_id, relay);
break;
@ -255,13 +264,11 @@ function fetch_thread_history(evid, pool) {
log_debug(`fetching thread ${sid}`);
}
function subscribe_explore(limit) {
DAMUS.pool.subscribe(SID_EXPLORE, [{
function fetch_friends_history(friends, pool, relay) {
pool.subscribe(SID_FRIENDS, [{
kinds: STANDARD_KINDS,
limit: limit,
}]);
authors: friends,
limit: 500,
}], relay);
}
function unsubscribe_explore() {
DAMUS.pool.unsubscribe(SID_EXPLORE);
}

View file

@ -51,6 +51,7 @@ function model_get_relay_que(model, relay) {
return map_get(model.relay_que, relay, {
profiles: [],
timestamp: 0,
contacts_init: false,
});
}

View file

@ -19,27 +19,15 @@ function view_timeline_apply_mode(model, mode, opts={}) {
el.dataset.threadId == thread_id))
return;
// Set the last time we were actively viewing explore to correctly fetch
// the history in the future
if (el.dataset.mode == VM_EXPLORE && mode != VM_EXPLORE) {
model.seen_explore = now;
}
if (mode == VM_EXPLORE) {
// If the time between the last explore and now is less than a minute
// simply only fetch a few
subscribe_explore((now - model.seen_explore) / 1000 < 60 ? 100 : 500);
} else {
unsubscribe_explore();
}
// Fetch history for certain views
if (mode == VM_THREAD || mode == VM_USER) {
fetch_thread_history(thread_id, model.pool);
view_show_spinner(true);
fetch_thread_history(thread_id, model.pool);
}
// Request the background info for this user
if (pubkey)
if (pubkey) {
view_show_spinner(true);
fetch_profile(pubkey, model.pool);
}
el.dataset.mode = mode;
switch(mode) {