MetadataCache -> CachedMetadata, addCachedMetadataToFuzzySearch
This commit is contained in:
6
packages/system/src/cache/index.ts
vendored
6
packages/system/src/cache/index.ts
vendored
@ -1,7 +1,7 @@
|
||||
import { FullRelaySettings, HexKey, NostrEvent, UserMetadata } from "..";
|
||||
import { hexToBech32, unixNowMs, DexieTableLike } from "@snort/shared";
|
||||
|
||||
export interface MetadataCache extends UserMetadata {
|
||||
export interface CachedMetadata extends UserMetadata {
|
||||
/**
|
||||
* When the object was saved in cache
|
||||
*/
|
||||
@ -58,7 +58,7 @@ export function mapEventToProfile(ev: NostrEvent) {
|
||||
npub: hexToBech32("npub", ev.pubkey),
|
||||
created: ev.created_at,
|
||||
loaded: unixNowMs(),
|
||||
} as MetadataCache;
|
||||
} as CachedMetadata;
|
||||
|
||||
// sanitize non-string/number
|
||||
for (const [k, v] of Object.entries(ret)) {
|
||||
@ -73,7 +73,7 @@ export function mapEventToProfile(ev: NostrEvent) {
|
||||
}
|
||||
|
||||
export interface SnortSystemDb {
|
||||
users: DexieTableLike<MetadataCache>;
|
||||
users: DexieTableLike<CachedMetadata>;
|
||||
relayMetrics: DexieTableLike<RelayMetrics>;
|
||||
userRelays: DexieTableLike<UsersRelays>;
|
||||
events: DexieTableLike<NostrEvent>;
|
||||
|
16
packages/system/src/cache/user-metadata.ts
vendored
16
packages/system/src/cache/user-metadata.ts
vendored
@ -1,17 +1,17 @@
|
||||
import { MetadataCache } from ".";
|
||||
import { CachedMetadata } from ".";
|
||||
import { fetchNip05Pubkey, FeedCache, LNURL, DexieTableLike } from "@snort/shared";
|
||||
|
||||
export class UserProfileCache extends FeedCache<MetadataCache> {
|
||||
export class UserProfileCache extends FeedCache<CachedMetadata> {
|
||||
#zapperQueue: Array<{ pubkey: string; lnurl: string }> = [];
|
||||
#nip5Queue: Array<{ pubkey: string; nip05: string }> = [];
|
||||
|
||||
constructor(table?: DexieTableLike<MetadataCache>) {
|
||||
constructor(table?: DexieTableLike<CachedMetadata>) {
|
||||
super("UserCache", table);
|
||||
this.#processZapperQueue();
|
||||
this.#processNip5Queue();
|
||||
}
|
||||
|
||||
key(of: MetadataCache): string {
|
||||
key(of: CachedMetadata): string {
|
||||
return of.pubkey;
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ export class UserProfileCache extends FeedCache<MetadataCache> {
|
||||
}
|
||||
}
|
||||
|
||||
async search(q: string): Promise<Array<MetadataCache>> {
|
||||
async search(q: string): Promise<Array<CachedMetadata>> {
|
||||
if (this.table) {
|
||||
// on-disk cache will always have more data
|
||||
return (
|
||||
@ -41,7 +41,7 @@ export class UserProfileCache extends FeedCache<MetadataCache> {
|
||||
} else {
|
||||
return [...this.cache.values()]
|
||||
.filter(user => {
|
||||
const profile = user as MetadataCache;
|
||||
const profile = user as CachedMetadata;
|
||||
return (
|
||||
profile.name?.includes(q) ||
|
||||
profile.npub?.includes(q) ||
|
||||
@ -58,7 +58,7 @@ export class UserProfileCache extends FeedCache<MetadataCache> {
|
||||
* @param m Profile metadata
|
||||
* @returns
|
||||
*/
|
||||
override async update(m: MetadataCache) {
|
||||
override async update(m: CachedMetadata) {
|
||||
const updateType = await super.update(m);
|
||||
if (updateType !== "refresh") {
|
||||
const lnurl = m.lud16 ?? m.lud06;
|
||||
@ -78,7 +78,7 @@ export class UserProfileCache extends FeedCache<MetadataCache> {
|
||||
return updateType;
|
||||
}
|
||||
|
||||
takeSnapshot(): MetadataCache[] {
|
||||
takeSnapshot(): CachedMetadata[] {
|
||||
return [...this.cache.values()];
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import { NoteStore } from "./note-collection";
|
||||
import { BuiltRawReqFilter, RequestBuilder } from "./request-builder";
|
||||
import { RelayMetricHandler } from "./relay-metric-handler";
|
||||
import {
|
||||
MetadataCache,
|
||||
CachedMetadata,
|
||||
ProfileLoaderService,
|
||||
RelayMetrics,
|
||||
SystemInterface,
|
||||
@ -38,7 +38,7 @@ export interface NostrSystemEvents {
|
||||
|
||||
export interface NostrsystemProps {
|
||||
relayCache?: FeedCache<UsersRelays>;
|
||||
profileCache?: FeedCache<MetadataCache>;
|
||||
profileCache?: FeedCache<CachedMetadata>;
|
||||
relayMetrics?: FeedCache<RelayMetrics>;
|
||||
eventsCache?: FeedCache<NostrEvent>;
|
||||
optimizer?: Optimizer;
|
||||
@ -62,7 +62,7 @@ export class NostrSystem extends EventEmitter<NostrSystemEvents> implements Syst
|
||||
/**
|
||||
* Storage class for user profiles
|
||||
*/
|
||||
#profileCache: FeedCache<MetadataCache>;
|
||||
#profileCache: FeedCache<CachedMetadata>;
|
||||
|
||||
/**
|
||||
* Storage class for relay metrics (connects/disconnects)
|
||||
|
@ -1,16 +1,16 @@
|
||||
import { unixNowMs } from "@snort/shared";
|
||||
import { EventKind, TaggedNostrEvent, RequestBuilder } from ".";
|
||||
import { ProfileCacheExpire } from "./const";
|
||||
import { mapEventToProfile, MetadataCache } from "./cache";
|
||||
import { mapEventToProfile, CachedMetadata } from "./cache";
|
||||
import { v4 as uuid } from "uuid";
|
||||
import { BackgroundLoader } from "./background-loader";
|
||||
|
||||
export class ProfileLoaderService extends BackgroundLoader<MetadataCache> {
|
||||
export class ProfileLoaderService extends BackgroundLoader<CachedMetadata> {
|
||||
override name(): string {
|
||||
return "ProfileLoaderService";
|
||||
}
|
||||
|
||||
override onEvent(e: Readonly<TaggedNostrEvent>): MetadataCache | undefined {
|
||||
override onEvent(e: Readonly<TaggedNostrEvent>): CachedMetadata | undefined {
|
||||
return mapEventToProfile(e);
|
||||
}
|
||||
|
||||
@ -30,11 +30,11 @@ export class ProfileLoaderService extends BackgroundLoader<MetadataCache> {
|
||||
return sub;
|
||||
}
|
||||
|
||||
protected override makePlaceholder(key: string): MetadataCache | undefined {
|
||||
protected override makePlaceholder(key: string): CachedMetadata | undefined {
|
||||
return {
|
||||
pubkey: key,
|
||||
loaded: unixNowMs() - ProfileCacheExpire + 30_000,
|
||||
created: 0,
|
||||
} as MetadataCache;
|
||||
} as CachedMetadata;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user