Fix long-running subscriptions clogging things up

This commit is contained in:
Jon Staab
2025-02-13 14:26:00 -08:00
parent 7f6a1bff34
commit 07dd1e97dc
6 changed files with 75 additions and 42 deletions
+8 -1
View File
@@ -8,6 +8,8 @@
const {value} = $props()
let hideImage = $state(false)
const url = value.url.toString()
const loadPreview = async () => {
@@ -20,6 +22,10 @@
return json
}
const onError = () => {
hideImage = true
}
const expand = () => pushModal(ContentLinkDetail, {url}, {fullscreen: true})
</script>
@@ -40,9 +46,10 @@
</div>
{:then preview}
<div class="bg-alt flex max-w-xl flex-col leading-normal">
{#if preview.image}
{#if preview.image && !hideImage}
<img
alt="Link preview"
onerror={onError}
src={imgproxy(preview.image)}
class="bg-alt max-h-72 object-contain object-center" />
{/if}
+8 -4
View File
@@ -1,5 +1,5 @@
import {get, writable} from "svelte/store"
import {partition, int, YEAR, MONTH, insert, sortBy, assoc, now} from "@welshman/lib"
import {partition, shuffle, int, YEAR, MONTH, insert, sortBy, assoc, now} from "@welshman/lib"
import {
MESSAGE,
DELETE,
@@ -285,13 +285,17 @@ export const makeCalendarFeed = ({
export const listenForNotifications = () => {
const subs: Subscription[] = []
for (const [url, rooms] of userRoomsByUrl.get()) {
for (const [url, allRooms] of userRoomsByUrl.get()) {
// Limit how many rooms we load at a time, since we have to send a separate filter
// for each one due to nip 29 breaking postel's law
const rooms = shuffle(Array.from(allRooms)).slice(0, 30)
load({
relays: [url],
filters: [
{kinds: [THREAD], limit: 1},
{kinds: [COMMENT], "#K": [String(THREAD)], limit: 1},
...Array.from(rooms).map(room => ({kinds: [MESSAGE], "#h": [room], limit: 1})),
...rooms.map(room => ({kinds: [MESSAGE], "#h": [room], limit: 1})),
],
})
@@ -301,7 +305,7 @@ export const listenForNotifications = () => {
filters: [
{kinds: [THREAD], since: now()},
{kinds: [COMMENT], "#K": [String(THREAD)], since: now()},
...Array.from(rooms).map(room => ({kinds: [MESSAGE], "#h": [room], since: now()})),
...rooms.map(room => ({kinds: [MESSAGE], "#h": [room], since: now()})),
],
}),
)