feat: in-memory fallback for storing user profiles #110
@ -8,7 +8,7 @@ import { Subscriptions } from "Nostr/Subscriptions";
|
||||
import { addDirectMessage, addNotifications, setFollows, setRelays } from "State/Login";
|
||||
import { RootState } from "State/Store";
|
||||
import { mapEventToProfile, MetadataCache } from "State/Users";
|
||||
import db from "State/Users/Db";
|
||||
import { getDb } from "State/Users/Db";
|
||||
import useSubscription from "Feed/Subscription";
|
||||
import { getDisplayName } from "Element/ProfileImage";
|
||||
import { MentionRegex } from "Const";
|
||||
@ -87,6 +87,7 @@ export default function useLoginFeed() {
|
||||
return acc;
|
||||
}, { created: 0, profile: <MetadataCache | null>null });
|
||||
if (maxProfile.profile) {
|
||||
const db = getDb()
|
||||
let existing = await db.find(maxProfile.profile.pubkey);
|
||||
if ((existing?.created ?? 0) < maxProfile.created) {
|
||||
await db.put(maxProfile.profile);
|
||||
@ -115,6 +116,7 @@ export default function useLoginFeed() {
|
||||
}
|
||||
|
||||
async function makeNotification(ev: TaggedRawEvent) {
|
||||
const db = getDb()
|
||||
switch (ev.kind) {
|
||||
case EventKind.TextNote: {
|
||||
const pubkeys = new Set([ev.pubkey, ...ev.tags.filter(a => a[0] === "p").map(a => a[1]!)]);
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { HexKey, TaggedRawEvent } from "Nostr";
|
||||
import { ProfileCacheExpire } from "Const";
|
||||
import { mapEventToProfile, MetadataCache, } from "State/Users";
|
||||
import db from "State/Users/Db";
|
||||
import { getDb } from "State/Users/Db";
|
||||
import Connection, { RelaySettings } from "Nostr/Connection";
|
||||
import Event from "Nostr/Event";
|
||||
import EventKind from "Nostr/EventKind";
|
||||
@ -167,6 +167,7 @@ export class NostrSystem {
|
||||
|
||||
async _FetchMetadata() {
|
||||
let missing = new Set<HexKey>();
|
||||
const db = getDb()
|
||||
let meta = await db.bulkGet(Array.from(this.WantsMetadata));
|
||||
let expire = new Date().getTime() - ProfileCacheExpire;
|
||||
for (let pk of this.WantsMetadata) {
|
||||
|
@ -144,4 +144,6 @@ indexedDb.isAvailable().then((available) => {
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
export default db
|
||||
Might as well try to open the SnortDb so we dont have a random "test" db be there forever Might as well try to open the SnortDb so we dont have a random "test" db be there forever
This seems to create an empty database and not store anything inside? This seems to create an empty database and not store anything inside?
I'll go back to using a dummy I'll go back to using a dummy `test` db with version 1 then, wdyt?
Still doesnt seem to actually use IndexdDb, in logs it says its using indexdb but its not storing anything there Still doesnt seem to actually use IndexdDb, in logs it says its using indexdb but its not storing anything there
My bad, My bad, https://github.com/v0l/snort/pull/110/commits/59878776d5a377e62937d1120c3b73a011a91c95 should fix it
|
||||
export function getDb() {
|
||||
Might as well try to open the SnortDb so we dont have a random "test" db be there forever Might as well try to open the SnortDb so we dont have a random "test" db be there forever
This seems to create an empty database and not store anything inside? This seems to create an empty database and not store anything inside?
I'll go back to using a dummy I'll go back to using a dummy `test` db with version 1 then, wdyt?
Still doesnt seem to actually use IndexdDb, in logs it says its using indexdb but its not storing anything there Still doesnt seem to actually use IndexdDb, in logs it says its using indexdb but its not storing anything there
My bad, My bad, https://github.com/v0l/snort/pull/110/commits/59878776d5a377e62937d1120c3b73a011a91c95 should fix it
|
||||
return db
|
||||
Might as well try to open the SnortDb so we dont have a random "test" db be there forever Might as well try to open the SnortDb so we dont have a random "test" db be there forever
This seems to create an empty database and not store anything inside? This seems to create an empty database and not store anything inside?
I'll go back to using a dummy I'll go back to using a dummy `test` db with version 1 then, wdyt?
Still doesnt seem to actually use IndexdDb, in logs it says its using indexdb but its not storing anything there Still doesnt seem to actually use IndexdDb, in logs it says its using indexdb but its not storing anything there
My bad, My bad, https://github.com/v0l/snort/pull/110/commits/59878776d5a377e62937d1120c3b73a011a91c95 should fix it
|
||||
}
|
||||
Might as well try to open the SnortDb so we dont have a random "test" db be there forever Might as well try to open the SnortDb so we dont have a random "test" db be there forever
This seems to create an empty database and not store anything inside? This seems to create an empty database and not store anything inside?
I'll go back to using a dummy I'll go back to using a dummy `test` db with version 1 then, wdyt?
Still doesnt seem to actually use IndexdDb, in logs it says its using indexdb but its not storing anything there Still doesnt seem to actually use IndexdDb, in logs it says its using indexdb but its not storing anything there
My bad, My bad, https://github.com/v0l/snort/pull/110/commits/59878776d5a377e62937d1120c3b73a011a91c95 should fix it
|
||||
|
||||
Might as well try to open the SnortDb so we dont have a random "test" db be there forever Might as well try to open the SnortDb so we dont have a random "test" db be there forever
Might as well try to open the SnortDb so we dont have a random "test" db be there forever Might as well try to open the SnortDb so we dont have a random "test" db be there forever
This seems to create an empty database and not store anything inside? This seems to create an empty database and not store anything inside?
This seems to create an empty database and not store anything inside? This seems to create an empty database and not store anything inside?
I'll go back to using a dummy I'll go back to using a dummy `test` db with version 1 then, wdyt?
I'll go back to using a dummy I'll go back to using a dummy `test` db with version 1 then, wdyt?
Still doesnt seem to actually use IndexdDb, in logs it says its using indexdb but its not storing anything there Still doesnt seem to actually use IndexdDb, in logs it says its using indexdb but its not storing anything there
Still doesnt seem to actually use IndexdDb, in logs it says its using indexdb but its not storing anything there Still doesnt seem to actually use IndexdDb, in logs it says its using indexdb but its not storing anything there
My bad, My bad, https://github.com/v0l/snort/pull/110/commits/59878776d5a377e62937d1120c3b73a011a91c95 should fix it
My bad, My bad, https://github.com/v0l/snort/pull/110/commits/59878776d5a377e62937d1120c3b73a011a91c95 should fix it
|
@ -1,11 +1,13 @@
|
||||
`db.find`?
`db.find`?
|
||||
import { useSelector } from "react-redux"
|
||||
import { useLiveQuery } from "dexie-react-hooks";
|
||||
import { MetadataCache } from "State/Users";
|
||||
import db, { inMemoryDb } from "State/Users/Db";
|
||||
`db.find`?
|
||||
import { getDb, inMemoryDb } from "State/Users/Db";
|
||||
`db.find`?
|
||||
import type { RootState } from "State/Store"
|
||||
import { HexKey } from "Nostr";
|
||||
|
||||
export function useQuery(query: string, limit: number = 5) {
|
||||
const db = getDb()
|
||||
`db.find`?
|
||||
|
||||
`db.find`?
|
||||
const allUsers = useLiveQuery(
|
||||
() => db.query(query)
|
||||
.catch((err) => {
|
||||
@ -20,6 +22,7 @@ export function useQuery(query: string, limit: number = 5) {
|
||||
`db.find`?
`db.find`?
|
||||
}
|
||||
|
||||
export function useKey(pubKey: HexKey) {
|
||||
const db = getDb()
|
||||
`db.find`?
|
||||
const { users } = useSelector((state: RootState) => state.users)
|
||||
const defaultUser = users[pubKey]
|
||||
|
||||
@ -38,6 +41,7 @@ export function useKey(pubKey: HexKey) {
|
||||
`db.find`?
`db.find`?
|
||||
}
|
||||
|
||||
export function useKeys(pubKeys: HexKey[]): Map<HexKey, MetadataCache> {
|
||||
const db = getDb()
|
||||
`db.find`?
|
||||
const dbUsers = useLiveQuery(async () => {
|
||||
if (pubKeys) {
|
||||
try {
|
||||
|
||||
`db.find`?
`db.find`?
|
Might as well try to open the SnortDb so we dont have a random "test" db be there forever
Might as well try to open the SnortDb so we dont have a random "test" db be there forever
This seems to create an empty database and not store anything inside?
This seems to create an empty database and not store anything inside?
I'll go back to using a dummy
test
db with version 1 then, wdyt?I'll go back to using a dummy
test
db with version 1 then, wdyt?Still doesnt seem to actually use IndexdDb, in logs it says its using indexdb but its not storing anything there
Still doesnt seem to actually use IndexdDb, in logs it says its using indexdb but its not storing anything there
My bad,
59878776d5
should fix itMy bad,
59878776d5
should fix it