feat: cache in settings

This commit is contained in:
Kieran 2023-10-19 19:25:33 +01:00
parent c96ea94bb3
commit 824b6fdce4
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
8 changed files with 129 additions and 2 deletions

View File

@ -372,5 +372,9 @@
<path fill-rule="evenodd" clip-rule="evenodd" d="M1.66699 4.9987C1.66699 4.07822 2.41318 3.33203 3.33366 3.33203C4.25413 3.33203 5.00033 4.07822 5.00033 4.9987C5.00033 5.91917 4.25413 6.66536 3.33366 6.66536C2.41318 6.66536 1.66699 5.91917 1.66699 4.9987Z" fill="currentColor"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M1.66699 14.9987C1.66699 14.0782 2.41318 13.332 3.33366 13.332C4.25413 13.332 5.00033 14.0782 5.00033 14.9987C5.00033 15.9192 4.25413 16.6654 3.33366 16.6654C2.41318 16.6654 1.66699 15.9192 1.66699 14.9987Z" fill="currentColor"/>
</symbol>
<symbol id="hard-drive" viewBox="0 0 24 24" fill="none">
<path d="M8.81413 2.99982C7.88643 2.99919 7.18706 2.99872 6.54986 3.21851C5.98936 3.41184 5.47885 3.72735 5.05527 4.14222C4.57372 4.61386 4.26137 5.23961 3.84705 6.06964C3.21363 7.33653 2.55478 8.59437 1.92983 9.86687C1.74859 10.2359 1.65797 10.4204 1.68168 10.5755C1.70218 10.7097 1.77888 10.8328 1.89025 10.9103C2.01902 11 2.22697 11 2.64287 11H21.3572C21.7731 11 21.9811 11 22.1098 10.9103C22.2212 10.8328 22.2979 10.7097 22.3184 10.5755C22.3421 10.4204 22.2515 10.2359 22.0702 9.86686C21.4453 8.59437 20.7865 7.33653 20.153 6.06966C19.7387 5.23961 19.4264 4.61386 18.9448 4.14222C18.5212 3.72735 18.0107 3.41184 17.4502 3.21851C16.813 2.99872 16.1136 2.99919 15.1859 2.99982H8.81413Z" fill="currentColor"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M23.0001 14.5996C23.0001 14.0399 23.0001 13.76 22.8912 13.5461C22.7953 13.3579 22.6423 13.2049 22.4541 13.109C22.2402 13 21.9603 13 21.4004 13H2.59962C2.03978 13 1.75985 13 1.54593 13.109C1.3578 13.2049 1.20476 13.3579 1.10891 13.5461C0.999925 13.76 0.999951 14.0399 1 14.5996C1.00002 14.8135 1.00004 15.0273 1.00004 15.2412C1.00003 16.0462 1.00002 16.7105 1.04423 17.2517C1.09016 17.8138 1.18872 18.3305 1.43601 18.8159C1.81951 19.5685 2.43143 20.1804 3.18408 20.5639C3.66941 20.8112 4.18612 20.9098 4.74821 20.9557C5.2894 20.9999 5.95376 20.9999 6.75872 20.9999H17.2414C18.0463 20.9999 18.7107 20.9999 19.2519 20.9557C19.814 20.9098 20.3307 20.8112 20.816 20.5639C21.5687 20.1804 22.1806 19.5685 22.5641 18.8159C22.8114 18.3305 22.9099 17.8138 22.9558 17.2517C23.0001 16.7105 23.0001 16.0462 23 15.2412C23 15.0274 23.0001 14.8135 23.0001 14.5996ZM6.00002 15C5.44773 15 5.00002 15.4477 5.00002 16C5.00002 16.5523 5.44773 17 6.00002 17H10C10.5523 17 11 16.5523 11 16C11 15.4477 10.5523 15 10 15H6.00002Z" fill="currentColor"/>
</symbol>
</defs>
</svg>

Before

Width:  |  Height:  |  Size: 98 KiB

After

Width:  |  Height:  |  Size: 100 KiB

View File

@ -9,7 +9,8 @@ import AccountsPage from "Pages/settings/Accounts";
import { WalletSettingsRoutes } from "Pages/settings/WalletSettings";
import { ManageHandleRoutes } from "Pages/settings/handle";
import ExportKeys from "Pages/settings/Keys";
import { ModerationSettings } from "./settings/Moderation";
import { ModerationSettings } from "Pages/settings/Moderation";
import { CacheSettings } from "./settings/Cache";
import messages from "./messages";
@ -61,6 +62,10 @@ export const SettingsRoutes: RouteObject[] = [
path: "moderation",
element: <ModerationSettings />,
},
{
path: "cache",
element: <CacheSettings />,
},
...ManageHandleRoutes,
...WalletSettingsRoutes,
],

View File

@ -0,0 +1,63 @@
import { FeedCache } from "@snort/shared";
import {
Chats,
FollowsFeed,
GiftsCache,
InteractionCache,
Notifications,
PaymentsCache,
RelayMetrics,
UserCache,
UserRelays,
} from "Cache";
import AsyncButton from "Element/AsyncButton";
import { ReactNode, useSyncExternalStore } from "react";
import { FormattedMessage, FormattedNumber } from "react-intl";
export function CacheSettings() {
return (
<div className="flex flex-col g8">
<h3>
<FormattedMessage defaultMessage="Cache" />
</h3>
<CacheDetails cache={UserCache} name={<FormattedMessage defaultMessage="Profiles" />} />
<CacheDetails cache={UserRelays} name={<FormattedMessage defaultMessage="Relay Lists" />} />
<CacheDetails cache={Notifications} name={<FormattedMessage defaultMessage="Notifications" />} />
<CacheDetails cache={FollowsFeed} name={<FormattedMessage defaultMessage="Follows Feed" />} />
<CacheDetails cache={Chats} name={<FormattedMessage defaultMessage="Chats" />} />
<CacheDetails cache={RelayMetrics} name={<FormattedMessage defaultMessage="Relay Metrics" />} />
<CacheDetails cache={PaymentsCache} name={<FormattedMessage defaultMessage="Payments" />} />
<CacheDetails cache={InteractionCache} name={<FormattedMessage defaultMessage="Interactions" />} />
<CacheDetails cache={GiftsCache} name={<FormattedMessage defaultMessage="Gift Wraps" />} />
</div>
);
}
function CacheDetails<T>({ cache, name }: { cache: FeedCache<T>; name: ReactNode }) {
const snapshot = useSyncExternalStore(
c => cache.hook(c, "*"),
() => cache.snapshot(),
);
return (
<div className="flex justify-between br p bg-superdark">
<div className="flex flex-col g4">
{name}
<small>
<FormattedMessage
defaultMessage="{count} ({count2} in memory)"
values={{
count: <FormattedNumber value={cache.keysOnTable().length} />,
count2: <FormattedNumber value={snapshot.length} />,
}}
/>
</small>
</div>
<div>
<AsyncButton onClick={() => cache.clear()}>
<FormattedMessage defaultMessage="Clear" />
</AsyncButton>
</div>
</div>
);
}

View File

@ -99,6 +99,11 @@ const SettingsIndex = () => {
<Icon name="arrowFront" size={16} />
</div>
)}
<div className="settings-row" onClick={() => navigate("cache")}>
<Icon name="hard-drive" size={24} />
<FormattedMessage defaultMessage="Cache" />
<Icon name="arrowFront" size={16} />
</div>
<div className="settings-row" onClick={handleLogout}>
<Icon name="logout" size={24} />
<FormattedMessage {...messages.LogOut} />

View File

@ -29,6 +29,9 @@
"/4tOwT": {
"defaultMessage": "Skip"
},
"/GCoTA": {
"defaultMessage": "Clear"
},
"/JE/X+": {
"defaultMessage": "Account Support"
},
@ -114,6 +117,9 @@
"2ukA4d": {
"defaultMessage": "{n} hours"
},
"2zJXeA": {
"defaultMessage": "Profiles"
},
"3KNMbJ": {
"defaultMessage": "Articles"
},
@ -288,6 +294,9 @@
"9wO4wJ": {
"defaultMessage": "Lightning Invoice"
},
"ABAQyo": {
"defaultMessage": "Chats"
},
"ADmfQT": {
"defaultMessage": "Parent",
"description": "Link to parent note in thread"
@ -377,6 +386,9 @@
"D3idYv": {
"defaultMessage": "Settings"
},
"DBiVK1": {
"defaultMessage": "Cache"
},
"DKnriN": {
"defaultMessage": "Send sats"
},
@ -1067,6 +1079,9 @@
"filwqD": {
"defaultMessage": "Read"
},
"fjAcWo": {
"defaultMessage": "Gift Wraps"
},
"flnGvv": {
"defaultMessage": "What's on your mind?"
},
@ -1094,6 +1109,9 @@
"gczcC5": {
"defaultMessage": "Subscribe"
},
"geppt8": {
"defaultMessage": "{count} ({count2} in memory)"
},
"gjBiyj": {
"defaultMessage": "Loading..."
},
@ -1145,6 +1163,9 @@
"iXPL0Z": {
"defaultMessage": "Can't login with private key on an insecure connection, please use a Nostr key manager extension instead"
},
"iYc3Ld": {
"defaultMessage": "Payments"
},
"ieGrWo": {
"defaultMessage": "Follow"
},
@ -1395,6 +1416,9 @@
"sZQzjQ": {
"defaultMessage": "Failed to parse zap split: {input}"
},
"tGXF0Q": {
"defaultMessage": "Relay Lists"
},
"tOdNiY": {
"defaultMessage": "Dark"
},
@ -1404,15 +1428,24 @@
"thnRpU": {
"defaultMessage": "Getting NIP-05 verified can help:"
},
"tjpYlr": {
"defaultMessage": "Relay Metrics"
},
"ttxS0b": {
"defaultMessage": "Supporter Badge"
},
"u+LyXc": {
"defaultMessage": "Interactions"
},
"u/vOPu": {
"defaultMessage": "Paid"
},
"u4bHcR": {
"defaultMessage": "Check out the code here: {link}"
},
"uKqSN+": {
"defaultMessage": "Follows Feed"
},
"uSV4Ti": {
"defaultMessage": "Reposts need to be manually confirmed"
},

View File

@ -9,6 +9,7 @@
"+vVZ/G": "Connect",
"+xliwN": "{name} reposted",
"/4tOwT": "Skip",
"/GCoTA": "Clear",
"/JE/X+": "Account Support",
"/PCavi": "Public",
"/RD0e2": "Nostr uses digital signature technology to provide tamper proof notes which can safely be replicated to many relays to provide redundant storage of your content.",
@ -37,6 +38,7 @@
"2a2YiP": "{n} Bookmarks",
"2k0Cv+": "Dislikes ({n})",
"2ukA4d": "{n} hours",
"2zJXeA": "Profiles",
"3KNMbJ": "Articles",
"3cc4Ct": "Light",
"3gOsZq": "Translators",
@ -94,6 +96,7 @@
"9kSari": "Retry publishing",
"9pMqYs": "Nostr Address",
"9wO4wJ": "Lightning Invoice",
"ABAQyo": "Chats",
"ADmfQT": "Parent",
"AN0Z7Q": "Muted Words",
"ASRK0S": "This author has been muted",
@ -123,6 +126,7 @@
"Cu/K85": "Translated from {lang}",
"D+KzKd": "Automatically zap every note when loaded",
"D3idYv": "Settings",
"DBiVK1": "Cache",
"DKnriN": "Send sats",
"DZzCem": "Show latest {n} notes",
"DcL8P+": "Supporter",
@ -349,6 +353,7 @@
"fOksnD": "Can't vote because LNURL service does not support zaps",
"fWZYP5": "Pinned",
"filwqD": "Read",
"fjAcWo": "Gift Wraps",
"flnGvv": "What's on your mind?",
"fqwcJ1": "On-chain Donation",
"fsB/4p": "Saved",
@ -358,6 +363,7 @@
"gDzDRs": "Emoji to send when reactiong to a note",
"gXgY3+": "Not all clients support this yet",
"gczcC5": "Subscribe",
"geppt8": "{count} ({count2} in memory)",
"gjBiyj": "Loading...",
"grQ+mI": "Proof of Work",
"h8XMJL": "Badges",
@ -375,6 +381,7 @@
"iGT1eE": "Prevent fake accounts from imitating you",
"iNWbVV": "Handle",
"iXPL0Z": "Can't login with private key on an insecure connection, please use a Nostr key manager extension instead",
"iYc3Ld": "Payments",
"ieGrWo": "Follow",
"itPgxd": "Profile",
"izWS4J": "Unfollow",
@ -457,12 +464,16 @@
"sKDn4e": "Show Badges",
"sUNhQE": "user",
"sZQzjQ": "Failed to parse zap split: {input}",
"tGXF0Q": "Relay Lists",
"tOdNiY": "Dark",
"th5lxp": "Send note to a subset of your write relays",
"thnRpU": "Getting NIP-05 verified can help:",
"tjpYlr": "Relay Metrics",
"ttxS0b": "Supporter Badge",
"u+LyXc": "Interactions",
"u/vOPu": "Paid",
"u4bHcR": "Check out the code here: {link}",
"uKqSN+": "Follows Feed",
"uSV4Ti": "Reposts need to be manually confirmed",
"uc0din": "Send sats splits to",
"ugyJnE": "Sending notes and other stuff",

View File

@ -46,6 +46,10 @@ export abstract class FeedCache<TCached> {
this.onTable = new Set<string>(keys.map(a => a as string));
}
keysOnTable() {
return [...this.onTable];
}
hook(fn: HookFn, key: string | undefined) {
if (!key) {
return () => {
@ -190,6 +194,8 @@ export abstract class FeedCache<TCached> {
await this.table?.clear();
this.cache.clear();
this.onTable.clear();
this.#changed = true;
this.#hooks.forEach(h => h.fn());
}
snapshot() {

View File

@ -79,7 +79,7 @@ export class UserProfileCache extends FeedCache<MetadataCache> {
}
takeSnapshot(): MetadataCache[] {
return [];
return [...this.cache.values()];
}
async #processZapperQueue() {