From bbc9c88957975fc4ebc79f2d7c2afe42546e7f3c Mon Sep 17 00:00:00 2001 From: Shaul Lavochkin Date: Sun, 15 Jun 2025 11:59:25 +0300 Subject: [PATCH 1/2] fix: turn logs on --- src/sqlite/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sqlite/index.ts b/src/sqlite/index.ts index 6c2a756..cfbd6e9 100644 --- a/src/sqlite/index.ts +++ b/src/sqlite/index.ts @@ -12,7 +12,7 @@ import { runMigrations } from './migrations' import * as schema from './schema' import { generateAllTriggers } from './triggers' import type { DriverQuery, Sqlite3Method } from './types' -const shouldLog = false +const shouldLog = true const log = (...params: any[]) => shouldLog && console.log(...params) let sqlite3: Sqlite3Static From d96732e41c97d4e768bf2df309e6938d3c6acc7c Mon Sep 17 00:00:00 2001 From: Shaul Lavochkin Date: Sun, 15 Jun 2025 16:57:53 +0300 Subject: [PATCH 2/2] fix: pr --- ...astermind.sql => 0000_dark_earthquake.sql} | 0 drizzle/meta/0000_snapshot.json | 2 +- drizzle/meta/_journal.json | 4 +- src/components/AppIcon.tsx | 69 --------------- src/components/Data.tsx | 2 +- src/components/Logo.tsx | 86 ------------------- src/components/Users/ManageUsers.tsx | 7 +- src/components/Users/UserTable.tsx | 4 +- src/consts/demoData.ts | 6 +- src/routes/Home.tsx | 12 +-- src/sqlite/index.ts | 16 ++-- src/sqlite/triggers.ts | 4 +- src/utils/createBatchFlusher.tsx | 1 + 13 files changed, 25 insertions(+), 188 deletions(-) rename drizzle/{0000_cloudy_lady_mastermind.sql => 0000_dark_earthquake.sql} (100%) delete mode 100644 src/components/AppIcon.tsx delete mode 100644 src/components/Logo.tsx diff --git a/drizzle/0000_cloudy_lady_mastermind.sql b/drizzle/0000_dark_earthquake.sql similarity index 100% rename from drizzle/0000_cloudy_lady_mastermind.sql rename to drizzle/0000_dark_earthquake.sql diff --git a/drizzle/meta/0000_snapshot.json b/drizzle/meta/0000_snapshot.json index 06d3111..6d733f6 100644 --- a/drizzle/meta/0000_snapshot.json +++ b/drizzle/meta/0000_snapshot.json @@ -1,7 +1,7 @@ { "version": "6", "dialect": "sqlite", - "id": "117096b9-3e0e-4184-8374-9ade719ba54a", + "id": "371fbe16-12a2-4f5d-ae54-cd465106824b", "prevId": "00000000-0000-0000-0000-000000000000", "tables": { "cells": { diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index d3964bd..3527ef7 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -5,8 +5,8 @@ { "idx": 0, "version": "6", - "when": 1749921339907, - "tag": "0000_cloudy_lady_mastermind", + "when": 1749995282393, + "tag": "0000_dark_earthquake", "breakpoints": true } ] diff --git a/src/components/AppIcon.tsx b/src/components/AppIcon.tsx deleted file mode 100644 index e3f532d..0000000 --- a/src/components/AppIcon.tsx +++ /dev/null @@ -1,69 +0,0 @@ -import type { Component } from 'solid-js' - -interface AppIconProps { - size?: number - class?: string -} - -export const AppIcon: Component = props => { - const size = props.size || 50 - - return ( - - - - {/* Purple-500 */} - {/* Pink-500 */} - - - - - - - - {/* Background circle */} - - - {/* Light beam */} - - - {/* Sync circle */} - - - {/* Dot in the middle */} - - - ) -} diff --git a/src/components/Data.tsx b/src/components/Data.tsx index 2833601..6ce529e 100644 --- a/src/components/Data.tsx +++ b/src/components/Data.tsx @@ -140,7 +140,7 @@ export const Data = () => {

{post.title}

{post.body}

- Author ID: {post.authorId} | Post ID: {post.id} + Author ID: {post.author_id} | Post ID: {post.id}

)} diff --git a/src/components/Logo.tsx b/src/components/Logo.tsx deleted file mode 100644 index c352b7c..0000000 --- a/src/components/Logo.tsx +++ /dev/null @@ -1,86 +0,0 @@ -import type { Component } from 'solid-js' - -interface LogoProps { - size?: 'sm' | 'md' | 'lg' | 'xl' - class?: string -} - -export const Logo: Component = props => { - const sizes = { - sm: 'h-8', - md: 'h-10', - lg: 'h-12', - xl: 'h-16' - } - - const sizeClass = sizes[props.size || 'md'] - - return ( -
- - {/* Gradient definitions */} - - - {/* Purple-500 */} - {/* Pink-500 */} - - - - - - - - {/* Light beam */} - - - {/* Sync circle */} - - - {/* Dot in the middle */} - - - {/* Text */} - - Lumi - - Sync - - - -
- ) -} diff --git a/src/components/Users/ManageUsers.tsx b/src/components/Users/ManageUsers.tsx index 41292de..38554c3 100644 --- a/src/components/Users/ManageUsers.tsx +++ b/src/components/Users/ManageUsers.tsx @@ -35,14 +35,15 @@ export const ManageUsers: Component = () => { setError(null) setSuccess(null) try { - await (await db).insert(schema.users).values({ + const database = await db + await database.insert(schema.users).values({ name: name.trim(), email: email.trim(), bio: bio.trim(), location: location.trim(), picture: getRandomRobot(users.length + 1), - isActive: true, - createdAt: new Date().toISOString() + is_active: true, + created_at: new Date().toISOString() }) setSuccess('User added successfully.') diff --git a/src/components/Users/UserTable.tsx b/src/components/Users/UserTable.tsx index 744aa5d..df3432a 100644 --- a/src/components/Users/UserTable.tsx +++ b/src/components/Users/UserTable.tsx @@ -298,12 +298,12 @@ export const UsersTable: Component<{ - {user.isActive ? 'Active' : 'Inactive'} + {user.is_active ? 'Active' : 'Inactive'} diff --git a/src/consts/demoData.ts b/src/consts/demoData.ts index 2efe03e..0672c3e 100644 --- a/src/consts/demoData.ts +++ b/src/consts/demoData.ts @@ -8,7 +8,7 @@ interface DemoUser { picture?: string bio?: string location?: string - isActive?: boolean + is_active?: boolean } interface DemoPost { @@ -113,7 +113,7 @@ export async function seedDemoData(db: SqliteRemoteDatabase) { picture: getRandomRobot(demoUsers.indexOf(u) + 1), bio: u.bio, location: u.location, - isActive: Math.random() < 0.5 + is_active: Math.random() < 0.5 })) ) .onConflictDoNothing() @@ -126,7 +126,7 @@ export async function seedDemoData(db: SqliteRemoteDatabase) { const postsToInsert = demoPosts.map(p => { const author_id = emailToIdMap[p.authorEmail] - if (!author_id) { + if (author_id === undefined) { throw new Error(`No user found for email ${p.authorEmail}`) } return { diff --git a/src/routes/Home.tsx b/src/routes/Home.tsx index b26ab68..1167f7c 100644 --- a/src/routes/Home.tsx +++ b/src/routes/Home.tsx @@ -1,24 +1,16 @@ +import { makePersisted } from '@solid-primitives/storage' import { type Component, createEffect, createSignal, - on, onMount, type Signal } from 'solid-js' -import { GameOfLifeCanvas } from '../components/GameOfLifeCanvas' import { ChangeLogTable } from '../components/ChangeLog' +import { GameOfLifeCanvas } from '../components/GameOfLifeCanvas' import { ManageUsers } from '../components/Users/ManageUsers' import { MoonIcon, SunIcon } from '../components/icons/ThemeIcons' -import { makePersisted } from '@solid-primitives/storage' -import { Logo } from '../components/Logo' import { useDb } from '../context/DbProvider' -import type { ChangeCallback } from '../sqlite' -import * as Comlink from 'comlink' -import type { ChangeLog } from '../sqlite/schema' -import ky from 'ky' -import { createBatchFlusher } from '../utils/createBatchFlusher' -import { setupWebsocket } from '../sync/socket' export const [isDarkMode, setIsDarkMode] = makePersisted( createSignal(window.matchMedia('(prefers-color-scheme: dark)').matches) ) diff --git a/src/sqlite/index.ts b/src/sqlite/index.ts index cfbd6e9..6f28df4 100644 --- a/src/sqlite/index.ts +++ b/src/sqlite/index.ts @@ -40,7 +40,7 @@ const initClient = async () => { name: path, initialCapacity: 10 }) - // await poolUtil.wipeFiles() + await poolUtil.wipeFiles() ;[client, db] = createClient({ url: path, poolUtil }, sqlite3) await client.execute(`PRAGMA foreign_keys = ON;`) await runMigrations(client) @@ -277,9 +277,9 @@ const notifyChangeLogSubscribers = (changes: schema.ChangeLog[]) => { const notifyBatched = () => { const { rows } = getNewChangeLogsSync(logCursor) if (rows.length === 0) return - // log( - // `Worker: Fetched ${rows.length} change logs since last cursor ${logCursor}` - // ) + log( + `Worker: Fetched ${rows.length} change logs since last cursor ${logCursor}` + ) logCursor = rows[0].id notifyChangeLogSubscribers(rows) @@ -300,13 +300,14 @@ const notify = () => { const onClientReady = async () => { log('Worker: Client is ready!') - + const all = await drizzleClient + .select({ id: schema.changeLog.id }) + .from(schema.changeLog) const [row] = await drizzleClient .select({ id: schema.changeLog.id }) .from(schema.changeLog) .orderBy(desc(schema.changeLog.id)) .limit(1) - logCursor = row ? row.id - 1000 : 0 const { rows } = await getNewChangeLogs(logCursor) notifyChangeLogSubscribers(rows) @@ -361,7 +362,6 @@ const getNewChangeLogsSync = (lastSeenLogId: number) => { ORDER BY id DESC`, [lastSeenLogId] ) - const rows = result.rows as any as schema.ChangeLog[] return { rows } @@ -482,7 +482,7 @@ function logFileSystemSupport() { ] checks.forEach(({ name, supported }) => { - console.log(`${name}: ${supported ? '✅ supported' : '❌ not supported'}`) + log(`${name}: ${supported ? '✅ supported' : '❌ not supported'}`) }) } diff --git a/src/sqlite/triggers.ts b/src/sqlite/triggers.ts index 7fb4319..6982afb 100644 --- a/src/sqlite/triggers.ts +++ b/src/sqlite/triggers.ts @@ -12,14 +12,12 @@ function isSqliteTable(t: any): t is SQLiteTable { export async function generateAllTriggers(client: Client) { const tables = Object.values(schema) - for (const tbl of tables) { - if (!isSqliteTable(tbl)) return + if (!isSqliteTable(tbl)) continue const { name: tblName, columns, primaryKeys } = getTableConfig(tbl) if (tblName === 'change_log') continue const allCols = columns.map(c => c.name) - console.log('allCols', allCols) const dynamicPkCols = primaryKeys?.flatMap(pk => pk.columns?.map(c => c.name) ?? []) ?? [] const pkCols = [ diff --git a/src/utils/createBatchFlusher.tsx b/src/utils/createBatchFlusher.tsx index dd3df26..cefd3fc 100644 --- a/src/utils/createBatchFlusher.tsx +++ b/src/utils/createBatchFlusher.tsx @@ -29,6 +29,7 @@ export function createBatchFlusher( console.error('Batch flush failed, retrying:', error) buffer = itemsToSend.concat(buffer) + if (!timer) timer = setTimeout(flush, maxDelay) } finally { inFlight = false