clean up and improve perf
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { NDKEvent, NDKUserProfile } from '@nostr-dev-kit/ndk';
|
||||
import { NDKEvent } from '@nostr-dev-kit/ndk';
|
||||
import { BaseDirectory, removeFile } from '@tauri-apps/api/fs';
|
||||
import { Platform } from '@tauri-apps/api/os';
|
||||
import Database from 'tauri-plugin-sql-api';
|
||||
@@ -6,7 +6,6 @@ import { Stronghold } from 'tauri-plugin-stronghold-api';
|
||||
|
||||
import { FULL_RELAYS } from '@stores/constants';
|
||||
|
||||
import { toRawEvent } from '@utils/rawEvent';
|
||||
import { Account, DBEvent, Relays, Widget } from '@utils/types';
|
||||
|
||||
export class LumeStorage {
|
||||
@@ -124,6 +123,7 @@ export class LumeStorage {
|
||||
|
||||
public async updateLastLogin() {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
this.account.last_login_at = now;
|
||||
return await this.db.execute(
|
||||
'UPDATE accounts SET last_login_at = $1 WHERE id = $2;',
|
||||
[now, this.account.id]
|
||||
@@ -298,38 +298,6 @@ export class LumeStorage {
|
||||
return results.length < 1;
|
||||
}
|
||||
|
||||
public async createMetadata(event: NDKEvent) {
|
||||
const rawEvent = toRawEvent(event);
|
||||
|
||||
return await this.db.execute(
|
||||
'INSERT OR IGNORE INTO metadata (id, event, author, kind, created_at) VALUES ($1, $2, $3, $4, $5);',
|
||||
[
|
||||
rawEvent.id,
|
||||
JSON.stringify(rawEvent),
|
||||
rawEvent.pubkey,
|
||||
rawEvent.kind,
|
||||
rawEvent.created_at,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public async createProfile(pubkey: string, profile: NDKUserProfile) {
|
||||
return await this.db.execute(
|
||||
'INSERT OR REPLACE INTO metadata (id, event, author, kind, created_at) VALUES ($1, $2, $3, $4, $5);',
|
||||
[pubkey, JSON.stringify(profile), pubkey, 0, Math.round(Date.now() / 1000)]
|
||||
);
|
||||
}
|
||||
|
||||
public async getMetadataByPubkey(pubkey: string) {
|
||||
const results: DBEvent[] = await this.db.select(
|
||||
'SELECT * FROM metadata WHERE author = $1 AND kind = "0" LIMIT 1;',
|
||||
[pubkey]
|
||||
);
|
||||
|
||||
if (results.length < 1) return null;
|
||||
return JSON.parse(results[0].event as string) as NDKEvent;
|
||||
}
|
||||
|
||||
public async getExplicitRelayUrls() {
|
||||
if (!this.account) return FULL_RELAYS;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user