fix: small performance tweaks
Some checks failed
Release / app (push) Has been cancelled

This commit is contained in:
2024-12-06 13:22:13 +00:00
parent 897bb46706
commit 0901e54ab6
8 changed files with 20 additions and 54 deletions

View File

@ -36,8 +36,11 @@ class ToasterSlots extends ExternalStore<Array<ToastNotification>> {
#eatToast() {
const now = unixNow();
this.#stack = this.#stack.filter(a => (a.expire ?? 0) > now);
this.notifyChange();
const newStack = this.#stack.filter(a => (a.expire ?? 0) > now);
if (newStack.length !== this.#stack.length) {
this.#stack = newStack;
this.notifyChange();
}
}
}

View File

@ -13,7 +13,7 @@ export function useNotificationsView() {
leaveOpen: true,
});
if (publicKey) {
rb.withFilter().kinds(kinds).tag("p", [publicKey]);
rb.withFilter().kinds(kinds).tag("p", [publicKey]).limit(100);
}
return rb;
}, [publicKey]);

View File

@ -1,43 +1,15 @@
import { useEffect, useMemo, useState } from "react";
import fuzzySearch from "@/Db/FuzzySearch";
import useTimelineFeed, { TimelineFeedOptions, TimelineSubject } from "@/Feed/TimelineFeed";
import { debounce } from "@/Utils";
import useWoT from "./useWoT";
const options: TimelineFeedOptions = { method: "LIMIT_UNTIL" };
export default function useProfileSearch(search: string) {
const [debouncedSearch, setDebouncedSearch] = useState(search);
useEffect(() => {
return debounce(500, () => {
setDebouncedSearch(search);
});
}, [search]);
const subject = useMemo(
() =>
({
type: "profile_keyword",
items: debouncedSearch ? [debouncedSearch] : [],
discriminator: debouncedSearch,
}) as TimelineSubject,
[debouncedSearch],
);
const feed = useTimelineFeed(subject, options);
const results = useMemo(() => {
return userSearch(search);
}, [search, feed]);
return results;
export default function useProfileSearch(search: string | undefined) {
return userSearch(search);
}
export function userSearch(search: string) {
export function userSearch(search: string | undefined) {
const wot = useWoT();
const searchString = search.trim();
const fuseResults = fuzzySearch.search(searchString);
const searchString = search?.trim() ?? "";
const fuseResults = (searchString?.length ?? 0) > 0 ? fuzzySearch.search(searchString) : [];
const followDistanceNormalizationFactor = 3;
const seenIds = new Set();

View File

@ -1,19 +1,11 @@
import { useMemo } from "react";
import { useNotificationsView } from "@/Feed/WorkerRelayView";
import useLogin from "@/Hooks/useLogin";
export function HasNotificationsMarker() {
const readNotifications = useLogin(s => s.readNotifications);
const notifications = useNotificationsView();
const latestNotification = useMemo(
() => notifications.reduce((acc, v) => (v.created_at > acc ? v.created_at : acc), 0),
[notifications],
);
const hasNotifications = useMemo(
() => latestNotification * 1000 > readNotifications,
[notifications, readNotifications],
);
const latestNotification = 0; // TODO: get latest timestamp
const hasNotifications = useMemo(() => latestNotification * 1000 > readNotifications, [readNotifications]);
if (hasNotifications) {
return (

View File

@ -20,7 +20,7 @@ const getExtra = () => {
};
export function LogoHeader({ showText = false }: { showText: boolean }) {
const { subscriptions } = useLogin();
const subscriptions = useLogin(s => s.subscriptions);
const currentSubscription = getCurrentSubscription(subscriptions);
const appName = CONFIG.appName === "iris" && isStPatricksDay() ? "Irish" : CONFIG.appName;