Remove unknown methods

This commit is contained in:
Thomas Mathews 2022-12-29 19:37:43 -08:00
parent 02f8b7706e
commit 9a3361750e
3 changed files with 0 additions and 136 deletions

View file

@ -24,7 +24,6 @@
<script defer src="js/model.js?v=1"></script>
<script defer src="js/contacts.js?v=1"></script>
<script defer src="js/event.js?v=1"></script>
<script defer src="js/unknowns.js?v=1"></script>
<script defer src="js/lib.js?v=1"></script>
<script defer src="js/main.js?v=1"></script>
</head>

View file

@ -203,35 +203,6 @@ function model_remove_reaction(model, evid, update_view) {
view_timeline_update_reaction(model, target_ev);
}
/* model_event_has_unknown_ids checks the event if there are any referenced keys with
* unknown user profiles in the provided scope.
*/
function model_event_has_unknown_ids(damus, ev) {
// make sure this event itself is removed from unknowns
if (ev.kind === 0)
delete damus.unknown_pks[ev.pubkey]
delete damus.unknown_ids[ev.id]
let got_some = false
for (const tag of ev.tags) {
if (tag.length >= 2) {
if (tag[0] === "p") {
const pk = tag[1]
if (!model_has_profile(damus, pk) && is_valid_id(pk)) {
got_some = true
damus.unknown_pks[pk] = make_unk(tag[2], ev)
}
} else if (tag[0] === "e") {
const evid = tag[1]
if (!model_has_event(damus, evid) && is_valid_id(evid)) {
got_some = true
damus.unknown_ids[evid] = make_unk(tag[2], ev)
}
}
}
}
return got_some
}
function model_is_event_deleted(model, evid) {
// we've already know it's deleted
if (model.deleted[evid])

View file

@ -1,106 +0,0 @@
function make_unk(hint, ev) {
const attempts = 0
const parent_created = ev.created_at
if (hint && hint !== "")
return {attempts, hint: hint.trim().toLowerCase(), parent_created}
return {attempts, parent_created}
}
function gather_unknown_hints(damus, pks, evids)
{
let relays = new Set()
for (const pk of pks) {
const unk = damus.unknown_pks[pk]
if (unk && unk.hint && unk.hint !== "")
relays.add(unk.hint)
}
for (const evid of evids) {
const unk = damus.unknown_ids[evid]
if (unk && unk.hint && unk.hint !== "")
relays.add(unk.hint)
}
return Array.from(relays)
}
function get_non_expired_unknowns(unks, type)
{
const MAX_ATTEMPTS = 2
function sort_parent_created(a_id, b_id) {
const a = unks[a_id]
const b = unks[b_id]
return b.parent_created - a.parent_created
}
let new_expired = 0
const ids = Object.keys(unks).sort(sort_parent_created).reduce((ids, unk_id) => {
if (ids.length >= 255)
return ids
const unk = unks[unk_id]
if (unk.attempts >= MAX_ATTEMPTS) {
if (!unk.expired) {
unk.expired = true
new_expired++
}
return ids
}
unk.attempts++
ids.push(unk_id)
return ids
}, [])
if (new_expired !== 0)
log_debug("Gave up looking for %d %s", new_expired, type)
return ids
}
function fetch_unknown_events(damus) {
let filters = []
const pks = get_non_expired_unknowns(damus.unknown_pks, 'profiles')
const evids = get_non_expired_unknowns(damus.unknown_ids, 'events')
const relays = gather_unknown_hints(damus, pks, evids)
for (const relay of relays) {
if (!damus.pool.has(relay)) {
log_debug("adding %s to relays to fetch unknown events", relay)
damus.pool.add(relay)
}
}
if (evids.length !== 0) {
const unk_kinds = STANDARD_KINDS;
filters.push({ids: evids, kinds: unk_kinds})
filters.push({"#e": evids, kinds: [KIND_NOTE, KIND_CHATROOM], limit: 100})
}
if (pks.length !== 0)
filters.push({authors: pks, kinds:[0]})
if (filters.length === 0)
return;
log_debug("fetching unknowns", filters)
damus.pool.subscribe('unknowns', filters)
}
function schedule_unknown_refetch(damus) {
// spams our CPU :(
return;
const INTERVAL = 5000
if (!damus.unknown_timer) {
log_debug("fetching unknown events now and in %d seconds", INTERVAL / 1000)
damus.unknown_timer = setTimeout(() => {
fetch_unknown_events(damus)
setTimeout(() => {
delete damus.unknown_timer
if (damus.but_wait_theres_more > 0) {
damus.but_wait_theres_more = 0
schedule_unknown_refetch(damus)
}
}, INTERVAL)
}, INTERVAL)
fetch_unknown_events(damus)
} else {
damus.but_wait_theres_more++
}
}