diff --git a/docs/erfaringer/spacetimedb_integrasjon.md b/docs/erfaringer/spacetimedb_integrasjon.md index 3cf63f9..225bb75 100644 --- a/docs/erfaringer/spacetimedb_integrasjon.md +++ b/docs/erfaringer/spacetimedb_integrasjon.md @@ -107,5 +107,26 @@ Ny modell: - SyncOutbox-events prosesseres hver 1. sekund - Støtter: `messages/insert`, `messages/delete`, `messages/update`, `message_reactions/insert`, `message_reactions/delete` +## 7. Subscription-begrensninger + +**SpacetimeDB-subscriptions støtter IKKE JOINs.** En subscription-query som `SELECT mr.* FROM message_reaction mr JOIN chat_message cm ON cm.id = mr.message_id WHERE ...` feiler stille — `onApplied` kalles aldri, og ingen data vises. + +Bruk kun enkle `SELECT * FROM tabell WHERE ...`-queries i `.subscribe([...])`. Filtrer heller klient-side etter at data er lastet. + +Eksempel: +```typescript +// FEIL — feiler stille, ingen data +.subscribe([ + `SELECT * FROM chat_message WHERE channel_id = '${id}'`, + `SELECT mr.* FROM message_reaction mr JOIN chat_message cm ON cm.id = mr.message_id WHERE cm.channel_id = '${id}'` +]); + +// RIKTIG — last alle reaksjoner, filtrer i koden +.subscribe([ + `SELECT * FROM chat_message WHERE channel_id = '${id}'`, + `SELECT * FROM message_reaction` +]); +``` + ### Fallback PG-polling adapter (`pg.svelte.ts`) brukes kun når SpacetimeDB ikke er konfigurert. Markeres som `readonly: true`. diff --git a/web/src/lib/chat/module_bindings/add_reaction_reducer.ts b/web/src/lib/chat/module_bindings/add_reaction_reducer.ts index 960ff42..b149d6b 100644 --- a/web/src/lib/chat/module_bindings/add_reaction_reducer.ts +++ b/web/src/lib/chat/module_bindings/add_reaction_reducer.ts @@ -1,19 +1,19 @@ -// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. - -/* eslint-disable */ -/* tslint:disable */ -import { - TypeBuilder as __TypeBuilder, - t as __t, - type AlgebraicTypeType as __AlgebraicTypeType, - type Infer as __Infer, -} from "spacetimedb"; - -export default { - messageId: __t.string(), - workspaceId: __t.string(), - userId: __t.string(), - userName: __t.string(), - reaction: __t.string(), -}; +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from "spacetimedb"; + +export default { + messageId: __t.string(), + workspaceId: __t.string(), + userId: __t.string(), + userName: __t.string(), + reaction: __t.string(), +}; diff --git a/web/src/lib/chat/module_bindings/clear_channel_reducer.ts b/web/src/lib/chat/module_bindings/clear_channel_reducer.ts index b10a442..2c4e9d6 100644 --- a/web/src/lib/chat/module_bindings/clear_channel_reducer.ts +++ b/web/src/lib/chat/module_bindings/clear_channel_reducer.ts @@ -1,15 +1,15 @@ -// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. - -/* eslint-disable */ -/* tslint:disable */ -import { - TypeBuilder as __TypeBuilder, - t as __t, - type AlgebraicTypeType as __AlgebraicTypeType, - type Infer as __Infer, -} from "spacetimedb"; - -export default { - channelId: __t.string(), -}; +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from "spacetimedb"; + +export default { + channelId: __t.string(), +}; diff --git a/web/src/lib/chat/module_bindings/edit_message_reducer.ts b/web/src/lib/chat/module_bindings/edit_message_reducer.ts index be173e2..d2d8810 100644 --- a/web/src/lib/chat/module_bindings/edit_message_reducer.ts +++ b/web/src/lib/chat/module_bindings/edit_message_reducer.ts @@ -1,17 +1,17 @@ -// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. - -/* eslint-disable */ -/* tslint:disable */ -import { - TypeBuilder as __TypeBuilder, - t as __t, - type AlgebraicTypeType as __AlgebraicTypeType, - type Infer as __Infer, -} from "spacetimedb"; - -export default { - id: __t.string(), - workspaceId: __t.string(), - newBody: __t.string(), -}; +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from "spacetimedb"; + +export default { + id: __t.string(), + workspaceId: __t.string(), + newBody: __t.string(), +}; diff --git a/web/src/lib/chat/module_bindings/index.ts b/web/src/lib/chat/module_bindings/index.ts index 8e99eb0..ff6dc55 100644 --- a/web/src/lib/chat/module_bindings/index.ts +++ b/web/src/lib/chat/module_bindings/index.ts @@ -156,3 +156,4 @@ export class DbConnection extends __DbConnectionImpl { return new SubscriptionBuilder(this); }; } + diff --git a/web/src/lib/chat/module_bindings/load_reactions_reducer.ts b/web/src/lib/chat/module_bindings/load_reactions_reducer.ts index 316ff43..059ac6e 100644 --- a/web/src/lib/chat/module_bindings/load_reactions_reducer.ts +++ b/web/src/lib/chat/module_bindings/load_reactions_reducer.ts @@ -1,15 +1,15 @@ -// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. - -/* eslint-disable */ -/* tslint:disable */ -import { - TypeBuilder as __TypeBuilder, - t as __t, - type AlgebraicTypeType as __AlgebraicTypeType, - type Infer as __Infer, -} from "spacetimedb"; - -export default { - reactionsJson: __t.string(), -}; +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from "spacetimedb"; + +export default { + reactionsJson: __t.string(), +}; diff --git a/web/src/lib/chat/module_bindings/message_reaction_table.ts b/web/src/lib/chat/module_bindings/message_reaction_table.ts index 730553a..6e120f9 100644 --- a/web/src/lib/chat/module_bindings/message_reaction_table.ts +++ b/web/src/lib/chat/module_bindings/message_reaction_table.ts @@ -1,19 +1,19 @@ -// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. - -/* eslint-disable */ -/* tslint:disable */ -import { - TypeBuilder as __TypeBuilder, - t as __t, - type AlgebraicTypeType as __AlgebraicTypeType, - type Infer as __Infer, -} from "spacetimedb"; - -export default __t.row({ - id: __t.u64().primaryKey(), - messageId: __t.string().name("message_id"), - userId: __t.string().name("user_id"), - userName: __t.string().name("user_name"), - reaction: __t.string(), -}); +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from "spacetimedb"; + +export default __t.row({ + id: __t.u64().primaryKey(), + messageId: __t.string().name("message_id"), + userId: __t.string().name("user_id"), + userName: __t.string().name("user_name"), + reaction: __t.string(), +}); diff --git a/web/src/lib/chat/module_bindings/remove_reaction_reducer.ts b/web/src/lib/chat/module_bindings/remove_reaction_reducer.ts index 63769f3..db8cb64 100644 --- a/web/src/lib/chat/module_bindings/remove_reaction_reducer.ts +++ b/web/src/lib/chat/module_bindings/remove_reaction_reducer.ts @@ -1,18 +1,18 @@ -// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. - -/* eslint-disable */ -/* tslint:disable */ -import { - TypeBuilder as __TypeBuilder, - t as __t, - type AlgebraicTypeType as __AlgebraicTypeType, - type Infer as __Infer, -} from "spacetimedb"; - -export default { - messageId: __t.string(), - workspaceId: __t.string(), - userId: __t.string(), - reaction: __t.string(), -}; +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from "spacetimedb"; + +export default { + messageId: __t.string(), + workspaceId: __t.string(), + userId: __t.string(), + reaction: __t.string(), +}; diff --git a/web/src/lib/chat/module_bindings/types.ts b/web/src/lib/chat/module_bindings/types.ts index 60ef5db..64a5308 100644 --- a/web/src/lib/chat/module_bindings/types.ts +++ b/web/src/lib/chat/module_bindings/types.ts @@ -42,3 +42,4 @@ export const SyncOutbox = __t.object("SyncOutbox", { synced: __t.bool(), }); export type SyncOutbox = __Infer; + diff --git a/web/src/lib/chat/module_bindings/types/reducers.ts b/web/src/lib/chat/module_bindings/types/reducers.ts index 2eab8c9..a77af42 100644 --- a/web/src/lib/chat/module_bindings/types/reducers.ts +++ b/web/src/lib/chat/module_bindings/types/reducers.ts @@ -25,3 +25,4 @@ export type LoadReactionsParams = __Infer; export type MarkSyncedParams = __Infer; export type RemoveReactionParams = __Infer; export type SendMessageParams = __Infer; + diff --git a/web/src/lib/chat/spacetime.svelte.ts b/web/src/lib/chat/spacetime.svelte.ts index 237a12e..67dfab7 100644 --- a/web/src/lib/chat/spacetime.svelte.ts +++ b/web/src/lib/chat/spacetime.svelte.ts @@ -325,7 +325,7 @@ export function createSpacetimeChat( edit, delete: del, react, - refresh: async () => { rebuildMessages(); }, + refresh: async () => { rebuildMessages(); await enrichFromPg(); }, destroy }; }