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()];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user