summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/context
diff options
context:
space:
mode:
authoradamelmore <[email protected]>2026-01-26 06:06:10 -0600
committeradamelmore <[email protected]>2026-01-26 06:08:09 -0600
commitc87232d5dfee75d117f450181457ebf328c6e5c6 (patch)
treee60105f57d4e9c67d56c1534fae398f0787d8557 /packages/app/src/context
parentd03c5f6b3f0ef9996776e082788cbc0889a75800 (diff)
downloadopencode-c87232d5dfee75d117f450181457ebf328c6e5c6.tar.gz
opencode-c87232d5dfee75d117f450181457ebf328c6e5c6.zip
perf(app): performance improvements
Diffstat (limited to 'packages/app/src/context')
-rw-r--r--packages/app/src/context/notification.tsx71
1 files changed, 63 insertions, 8 deletions
diff --git a/packages/app/src/context/notification.tsx b/packages/app/src/context/notification.tsx
index 1c5953b3f..5e35f6ac0 100644
--- a/packages/app/src/context/notification.tsx
+++ b/packages/app/src/context/notification.tsx
@@ -1,5 +1,5 @@
import { createStore } from "solid-js/store"
-import { createEffect, onCleanup } from "solid-js"
+import { createEffect, createMemo, onCleanup } from "solid-js"
import { useParams } from "@solidjs/router"
import { createSimpleContext } from "@opencode-ai/ui/context"
import { useGlobalSDK } from "./global-sdk"
@@ -52,6 +52,15 @@ export const { use: useNotification, provider: NotificationProvider } = createSi
const settings = useSettings()
const language = useLanguage()
+ const empty: Notification[] = []
+
+ const currentDirectory = createMemo(() => {
+ if (!params.dir) return
+ return base64Decode(params.dir)
+ })
+
+ const currentSession = createMemo(() => params.id)
+
const [store, setStore, _, ready] = persisted(
Persist.global("notification", ["notification.v1"]),
createStore({
@@ -72,13 +81,59 @@ export const { use: useNotification, provider: NotificationProvider } = createSi
setStore("list", (list) => pruneNotifications([...list, notification]))
}
+ const index = createMemo(() => {
+ const sessionAll = new Map<string, Notification[]>()
+ const sessionUnseen = new Map<string, Notification[]>()
+ const projectAll = new Map<string, Notification[]>()
+ const projectUnseen = new Map<string, Notification[]>()
+
+ for (const notification of store.list) {
+ const session = notification.session
+ if (session) {
+ const list = sessionAll.get(session)
+ if (list) list.push(notification)
+ else sessionAll.set(session, [notification])
+ if (!notification.viewed) {
+ const unseen = sessionUnseen.get(session)
+ if (unseen) unseen.push(notification)
+ else sessionUnseen.set(session, [notification])
+ }
+ }
+
+ const directory = notification.directory
+ if (directory) {
+ const list = projectAll.get(directory)
+ if (list) list.push(notification)
+ else projectAll.set(directory, [notification])
+ if (!notification.viewed) {
+ const unseen = projectUnseen.get(directory)
+ if (unseen) unseen.push(notification)
+ else projectUnseen.set(directory, [notification])
+ }
+ }
+ }
+
+ return {
+ session: {
+ all: sessionAll,
+ unseen: sessionUnseen,
+ },
+ project: {
+ all: projectAll,
+ unseen: projectUnseen,
+ },
+ }
+ })
+
const unsub = globalSDK.event.listen((e) => {
- const directory = e.name
const event = e.details
+ if (event.type !== "session.idle" && event.type !== "session.error") return
+
+ const directory = e.name
const time = Date.now()
- const activeDirectory = params.dir ? base64Decode(params.dir) : undefined
- const activeSession = params.id
const viewed = (sessionID?: string) => {
+ const activeDirectory = currentDirectory()
+ const activeSession = currentSession()
if (!activeDirectory) return false
if (!activeSession) return false
if (!sessionID) return false
@@ -148,10 +203,10 @@ export const { use: useNotification, provider: NotificationProvider } = createSi
ready,
session: {
all(session: string) {
- return store.list.filter((n) => n.session === session)
+ return index().session.all.get(session) ?? empty
},
unseen(session: string) {
- return store.list.filter((n) => n.session === session && !n.viewed)
+ return index().session.unseen.get(session) ?? empty
},
markViewed(session: string) {
setStore("list", (n) => n.session === session, "viewed", true)
@@ -159,10 +214,10 @@ export const { use: useNotification, provider: NotificationProvider } = createSi
},
project: {
all(directory: string) {
- return store.list.filter((n) => n.directory === directory)
+ return index().project.all.get(directory) ?? empty
},
unseen(directory: string) {
- return store.list.filter((n) => n.directory === directory && !n.viewed)
+ return index().project.unseen.get(directory) ?? empty
},
markViewed(directory: string) {
setStore("list", (n) => n.directory === directory, "viewed", true)