Move the event parser and dedup functions to Rust (#206)
* feat: improve js parser * feat: move parser and dedup to rust * fix: parser * fix: get event function * feat: improve parser performance (#207) * feat: improve parser performance * feat: add test for video parsing * feat: finish new parser --------- Co-authored-by: XIAO YU <xyzmhx@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { EventWithReplies, Kind, NostrEvent } from "@lume/types";
|
||||
import type { EventWithReplies, Kind, Meta, NostrEvent } from "@lume/types";
|
||||
import { commands } from "./commands";
|
||||
import { generateContentTags } from "@lume/utils";
|
||||
|
||||
@@ -11,6 +11,7 @@ export class LumeEvent {
|
||||
public content: string;
|
||||
public sig: string;
|
||||
public relay?: string;
|
||||
public meta: Meta;
|
||||
#raw: NostrEvent;
|
||||
|
||||
constructor(event: NostrEvent) {
|
||||
@@ -74,9 +75,17 @@ export class LumeEvent {
|
||||
const query = await commands.getReplies(id);
|
||||
|
||||
if (query.status === "ok") {
|
||||
const events = query.data.map(
|
||||
(item) => JSON.parse(item) as EventWithReplies,
|
||||
);
|
||||
const events = query.data.map((item) => {
|
||||
const raw = JSON.parse(item.raw) as EventWithReplies;
|
||||
|
||||
if (item.parsed) {
|
||||
raw.meta = item.parsed;
|
||||
} else {
|
||||
raw.meta = null;
|
||||
}
|
||||
|
||||
return raw;
|
||||
});
|
||||
|
||||
if (events.length > 0) {
|
||||
const replies = new Set();
|
||||
@@ -135,7 +144,7 @@ export class LumeEvent {
|
||||
const queryReply = await commands.getEvent(reply_to);
|
||||
|
||||
if (queryReply.status === "ok") {
|
||||
const replyEvent = JSON.parse(queryReply.data) as NostrEvent;
|
||||
const replyEvent = JSON.parse(queryReply.data.raw) as NostrEvent;
|
||||
const relayHint =
|
||||
replyEvent.tags.find((ev) => ev[0] === "e")?.[0][2] ?? "";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user