feat: in-memory fallback for storing user profiles #110

Merged
verbiricha merged 17 commits from dbfix into main 2023-01-27 21:38:42 +00:00
4 changed files with 13 additions and 4 deletions
Showing only changes of commit 59878776d5 - Show all commits

View File

@ -8,7 +8,7 @@ import { Subscriptions } from "Nostr/Subscriptions";
import { addDirectMessage, addNotifications, setFollows, setRelays } from "State/Login"; import { addDirectMessage, addNotifications, setFollows, setRelays } from "State/Login";
import { RootState } from "State/Store"; import { RootState } from "State/Store";
import { mapEventToProfile, MetadataCache } from "State/Users"; import { mapEventToProfile, MetadataCache } from "State/Users";
import db from "State/Users/Db"; import { getDb } from "State/Users/Db";
import useSubscription from "Feed/Subscription"; import useSubscription from "Feed/Subscription";
import { getDisplayName } from "Element/ProfileImage"; import { getDisplayName } from "Element/ProfileImage";
import { MentionRegex } from "Const"; import { MentionRegex } from "Const";
@ -87,6 +87,7 @@ export default function useLoginFeed() {
return acc; return acc;
}, { created: 0, profile: <MetadataCache | null>null }); }, { created: 0, profile: <MetadataCache | null>null });
if (maxProfile.profile) { if (maxProfile.profile) {
const db = getDb()
let existing = await db.find(maxProfile.profile.pubkey); let existing = await db.find(maxProfile.profile.pubkey);
if ((existing?.created ?? 0) < maxProfile.created) { if ((existing?.created ?? 0) < maxProfile.created) {
await db.put(maxProfile.profile); await db.put(maxProfile.profile);
@ -115,6 +116,7 @@ export default function useLoginFeed() {
} }
async function makeNotification(ev: TaggedRawEvent) { async function makeNotification(ev: TaggedRawEvent) {
const db = getDb()
switch (ev.kind) { switch (ev.kind) {
case EventKind.TextNote: { case EventKind.TextNote: {
const pubkeys = new Set([ev.pubkey, ...ev.tags.filter(a => a[0] === "p").map(a => a[1]!)]); const pubkeys = new Set([ev.pubkey, ...ev.tags.filter(a => a[0] === "p").map(a => a[1]!)]);

View File

@ -1,7 +1,7 @@
import { HexKey, TaggedRawEvent } from "Nostr"; import { HexKey, TaggedRawEvent } from "Nostr";
import { ProfileCacheExpire } from "Const"; import { ProfileCacheExpire } from "Const";
import { mapEventToProfile, MetadataCache, } from "State/Users"; 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 Connection, { RelaySettings } from "Nostr/Connection";
import Event from "Nostr/Event"; import Event from "Nostr/Event";
import EventKind from "Nostr/EventKind"; import EventKind from "Nostr/EventKind";
@ -167,6 +167,7 @@ export class NostrSystem {
async _FetchMetadata() { async _FetchMetadata() {
let missing = new Set<HexKey>(); let missing = new Set<HexKey>();
const db = getDb()
let meta = await db.bulkGet(Array.from(this.WantsMetadata)); let meta = await db.bulkGet(Array.from(this.WantsMetadata));
let expire = new Date().getTime() - ProfileCacheExpire; let expire = new Date().getTime() - ProfileCacheExpire;
for (let pk of this.WantsMetadata) { for (let pk of this.WantsMetadata) {

View File

@ -144,4 +144,6 @@ indexedDb.isAvailable().then((available) => {
v0l commented 2023-01-23 13:30:52 +00:00 (Migrated from github.com)
Review

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
v0l commented 2023-01-23 13:30:52 +00:00 (Migrated from github.com)
Review

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
v0l commented 2023-01-25 10:03:35 +00:00 (Migrated from github.com)
Review

This seems to create an empty database and not store anything inside?

This seems to create an empty database and not store anything inside?
v0l commented 2023-01-25 10:03:35 +00:00 (Migrated from github.com)
Review

This seems to create an empty database and not store anything inside?

This seems to create an empty database and not store anything inside?
verbiricha commented 2023-01-25 16:57:56 +00:00 (Migrated from github.com)
Review

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?
verbiricha commented 2023-01-25 16:57:56 +00:00 (Migrated from github.com)
Review

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?
v0l commented 2023-01-25 17:33:25 +00:00 (Migrated from github.com)
Review

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
v0l commented 2023-01-25 17:33:25 +00:00 (Migrated from github.com)
Review

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
verbiricha commented 2023-01-27 09:06:04 +00:00 (Migrated from github.com)
Review

My bad, 59878776d5 should fix it

My bad, https://github.com/v0l/snort/pull/110/commits/59878776d5a377e62937d1120c3b73a011a91c95 should fix it
verbiricha commented 2023-01-27 09:06:04 +00:00 (Migrated from github.com)
Review

My bad, 59878776d5 should fix it

My bad, https://github.com/v0l/snort/pull/110/commits/59878776d5a377e62937d1120c3b73a011a91c95 should fix it
} }
}) })
export default db export function getDb() {
v0l commented 2023-01-23 13:30:52 +00:00 (Migrated from github.com)
Review

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
v0l commented 2023-01-25 10:03:35 +00:00 (Migrated from github.com)
Review

This seems to create an empty database and not store anything inside?

This seems to create an empty database and not store anything inside?
verbiricha commented 2023-01-25 16:57:56 +00:00 (Migrated from github.com)
Review

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?
v0l commented 2023-01-25 17:33:25 +00:00 (Migrated from github.com)
Review

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
verbiricha commented 2023-01-27 09:06:04 +00:00 (Migrated from github.com)
Review

My bad, 59878776d5 should fix it

My bad, https://github.com/v0l/snort/pull/110/commits/59878776d5a377e62937d1120c3b73a011a91c95 should fix it
v0l commented 2023-01-23 13:30:52 +00:00 (Migrated from github.com)
Review

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
v0l commented 2023-01-25 10:03:35 +00:00 (Migrated from github.com)
Review

This seems to create an empty database and not store anything inside?

This seems to create an empty database and not store anything inside?
verbiricha commented 2023-01-25 16:57:56 +00:00 (Migrated from github.com)
Review

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?
v0l commented 2023-01-25 17:33:25 +00:00 (Migrated from github.com)
Review

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
verbiricha commented 2023-01-27 09:06:04 +00:00 (Migrated from github.com)
Review

My bad, 59878776d5 should fix it

My bad, https://github.com/v0l/snort/pull/110/commits/59878776d5a377e62937d1120c3b73a011a91c95 should fix it
return db
v0l commented 2023-01-23 13:30:52 +00:00 (Migrated from github.com)
Review

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
v0l commented 2023-01-25 10:03:35 +00:00 (Migrated from github.com)
Review

This seems to create an empty database and not store anything inside?

This seems to create an empty database and not store anything inside?
verbiricha commented 2023-01-25 16:57:56 +00:00 (Migrated from github.com)
Review

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?
v0l commented 2023-01-25 17:33:25 +00:00 (Migrated from github.com)
Review

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
verbiricha commented 2023-01-27 09:06:04 +00:00 (Migrated from github.com)
Review

My bad, 59878776d5 should fix it

My bad, https://github.com/v0l/snort/pull/110/commits/59878776d5a377e62937d1120c3b73a011a91c95 should fix it
}
v0l commented 2023-01-23 13:30:52 +00:00 (Migrated from github.com)
Review

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
v0l commented 2023-01-25 10:03:35 +00:00 (Migrated from github.com)
Review

This seems to create an empty database and not store anything inside?

This seems to create an empty database and not store anything inside?
verbiricha commented 2023-01-25 16:57:56 +00:00 (Migrated from github.com)
Review

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?
v0l commented 2023-01-25 17:33:25 +00:00 (Migrated from github.com)
Review

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
verbiricha commented 2023-01-27 09:06:04 +00:00 (Migrated from github.com)
Review

My bad, 59878776d5 should fix it

My bad, https://github.com/v0l/snort/pull/110/commits/59878776d5a377e62937d1120c3b73a011a91c95 should fix it

v0l commented 2023-01-23 13:30:52 +00:00 (Migrated from github.com)
Review

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
v0l commented 2023-01-23 13:30:52 +00:00 (Migrated from github.com)
Review

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
v0l commented 2023-01-25 10:03:35 +00:00 (Migrated from github.com)
Review

This seems to create an empty database and not store anything inside?

This seems to create an empty database and not store anything inside?
v0l commented 2023-01-25 10:03:35 +00:00 (Migrated from github.com)
Review

This seems to create an empty database and not store anything inside?

This seems to create an empty database and not store anything inside?
verbiricha commented 2023-01-25 16:57:56 +00:00 (Migrated from github.com)
Review

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?
verbiricha commented 2023-01-25 16:57:56 +00:00 (Migrated from github.com)
Review

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?
v0l commented 2023-01-25 17:33:25 +00:00 (Migrated from github.com)
Review

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
v0l commented 2023-01-25 17:33:25 +00:00 (Migrated from github.com)
Review

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
verbiricha commented 2023-01-27 09:06:04 +00:00 (Migrated from github.com)
Review

My bad, 59878776d5 should fix it

My bad, https://github.com/v0l/snort/pull/110/commits/59878776d5a377e62937d1120c3b73a011a91c95 should fix it
verbiricha commented 2023-01-27 09:06:04 +00:00 (Migrated from github.com)
Review

My bad, 59878776d5 should fix it

My bad, https://github.com/v0l/snort/pull/110/commits/59878776d5a377e62937d1120c3b73a011a91c95 should fix it

View File

@ -1,11 +1,13 @@
v0l commented 2023-01-23 12:43:41 +00:00 (Migrated from github.com)
Review

db.find?

`db.find`?
v0l commented 2023-01-23 12:43:41 +00:00 (Migrated from github.com)
Review

db.find?

`db.find`?
import { useSelector } from "react-redux" import { useSelector } from "react-redux"
import { useLiveQuery } from "dexie-react-hooks"; import { useLiveQuery } from "dexie-react-hooks";
import { MetadataCache } from "State/Users"; import { MetadataCache } from "State/Users";
import db, { inMemoryDb } from "State/Users/Db"; import { getDb, inMemoryDb } from "State/Users/Db";
v0l commented 2023-01-23 12:43:41 +00:00 (Migrated from github.com)
Review

db.find?

`db.find`?
v0l commented 2023-01-23 12:43:41 +00:00 (Migrated from github.com)
Review

db.find?

`db.find`?
import type { RootState } from "State/Store" import type { RootState } from "State/Store"
import { HexKey } from "Nostr"; import { HexKey } from "Nostr";
export function useQuery(query: string, limit: number = 5) { export function useQuery(query: string, limit: number = 5) {
const db = getDb()
v0l commented 2023-01-23 12:43:41 +00:00 (Migrated from github.com)
Review

db.find?

`db.find`?
v0l commented 2023-01-23 12:43:41 +00:00 (Migrated from github.com)
Review

db.find?

`db.find`?
const allUsers = useLiveQuery( const allUsers = useLiveQuery(
() => db.query(query) () => db.query(query)
.catch((err) => { .catch((err) => {
@ -20,6 +22,7 @@ export function useQuery(query: string, limit: number = 5) {
v0l commented 2023-01-23 12:43:41 +00:00 (Migrated from github.com)
Review

db.find?

`db.find`?
v0l commented 2023-01-23 12:43:41 +00:00 (Migrated from github.com)
Review

db.find?

`db.find`?
} }
export function useKey(pubKey: HexKey) { export function useKey(pubKey: HexKey) {
const db = getDb()
v0l commented 2023-01-23 12:43:41 +00:00 (Migrated from github.com)
Review

db.find?

`db.find`?
const { users } = useSelector((state: RootState) => state.users) const { users } = useSelector((state: RootState) => state.users)
const defaultUser = users[pubKey] const defaultUser = users[pubKey]
@ -38,6 +41,7 @@ export function useKey(pubKey: HexKey) {
v0l commented 2023-01-23 12:43:41 +00:00 (Migrated from github.com)
Review

db.find?

`db.find`?
v0l commented 2023-01-23 12:43:41 +00:00 (Migrated from github.com)
Review

db.find?

`db.find`?
} }
export function useKeys(pubKeys: HexKey[]): Map<HexKey, MetadataCache> { export function useKeys(pubKeys: HexKey[]): Map<HexKey, MetadataCache> {
const db = getDb()
v0l commented 2023-01-23 12:43:41 +00:00 (Migrated from github.com)
Review

db.find?

`db.find`?
const dbUsers = useLiveQuery(async () => { const dbUsers = useLiveQuery(async () => {
if (pubKeys) { if (pubKeys) {
try { try {

v0l commented 2023-01-23 12:43:41 +00:00 (Migrated from github.com)
Review

db.find?

`db.find`?
v0l commented 2023-01-23 12:43:41 +00:00 (Migrated from github.com)
Review

db.find?

`db.find`?