fix idb unique indexes

This commit is contained in:
Martti Malmi
2024-01-05 00:09:46 +02:00
parent c4b74b3cb1
commit 956871e5e5
2 changed files with 8 additions and 6 deletions

View File

@ -27,10 +27,10 @@ class IndexedDB extends Dexie {
constructor() { constructor() {
super("EventDB"); super("EventDB");
this.version(5).stores({ this.version(6).stores({
// TODO use multientry index for *tags // TODO use multientry index for *tags
events: "id, pubkey, kind, created_at, [pubkey+kind]", events: "++id, pubkey, kind, created_at, [pubkey+kind]",
tags: "id, eventId, [type+value]", tags: "&[type+value+eventId], [type+value], eventId",
}); });
this.startInterval(); this.startInterval();
@ -87,7 +87,6 @@ class IndexedDB extends Dexie {
return false; return false;
}) })
.map(tag => ({ .map(tag => ({
id: event.id.slice(0, 16) + "-" + tag[0].slice(0, 16) + "-" + tag[1].slice(0, 16),
eventId: event.id, eventId: event.id,
type: tag[0], type: tag[0],
value: tag[1], value: tag[1],
@ -173,7 +172,7 @@ class IndexedDB extends Dexie {
let hasTags = false; let hasTags = false;
for (const key in filter) { for (const key in filter) {
if (filter.hasOwnProperty(key) && key.startsWith("#")) { if (key.startsWith("#")) {
hasTags = true; hasTags = true;
const tagName = key.slice(1); // Remove the hash to get the tag name const tagName = key.slice(1); // Remove the hash to get the tag name
const values = filter[key]; const values = filter[key];
@ -215,6 +214,9 @@ class IndexedDB extends Dexie {
} }
if (filter.search) { if (filter.search) {
const term = filter.search.replace(" sort:popular", ""); const term = filter.search.replace(" sort:popular", "");
if (term === "") {
return;
}
const regexp = new RegExp(term, "i"); const regexp = new RegExp(term, "i");
query = query.filter((event: Event) => event.content?.match(regexp)); query = query.filter((event: Event) => event.content?.match(regexp));
} }

View File

@ -1,3 +1,4 @@
import { base64 } from "@scure/base";
import { unixNow, unwrap } from "@snort/shared"; import { unixNow, unwrap } from "@snort/shared";
import { OAuthToken } from "@/Pages/settings/wallet/Alby"; import { OAuthToken } from "@/Pages/settings/wallet/Alby";
@ -12,7 +13,6 @@ import {
WalletInvoice, WalletInvoice,
WalletInvoiceState, WalletInvoiceState,
} from "."; } from ".";
import { base64 } from "@scure/base";
export default class AlbyWallet implements LNWallet { export default class AlbyWallet implements LNWallet {
#token: OAuthToken; #token: OAuthToken;