π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
feat: ltar realtime
DarkPhoenix27046941b8195640
diff --git a/packages/nc-gui/composables/useLTARStore.ts b/packages/nc-gui/composables/useLTARStore.tsindex 6cd9cccde6..a257ea44ce 100644--- a/packages/nc-gui/composables/useLTARStore.ts+++ b/packages/nc-gui/composables/useLTARStore.ts@@ -36,6 +36,10 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(currentRow.value = row.value}+ if (isEeUI) {+ _reloadData = (_params: { shouldShowLoading?: boolean }) => {}+ }+// stateconst { metas, getMeta } = useMetas()@@ -55,7 +59,7 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(const path = inject(GroupPathInj, ref([]))// In canvas _reloadData will not work as we unmount editable component so on undo/redo we have to manually trigger view reload- const reloadViewDataTrigger = inject(ReloadViewDataHookInj, createEventHook())+ const reloadViewDataTrigger = isEeUI ? createEventHook() : inject(ReloadViewDataHookInj, createEventHook())const { addUndo, clone, defineViewScope } = useUndoRedo()diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.tsindex 0cb3334e41..7288bd554f 100644--- a/packages/nocodb/src/db/BaseModelSqlv2.ts+++ b/packages/nocodb/src/db/BaseModelSqlv2.ts@@ -2728,6 +2728,7 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {pks: string[];chunkSize?: number;apiVersion?: NcApiVersion;+ args?: Record<string, any>;}) {const { pks, chunkSize = 1000 } = args;@@ -2740,6 +2741,7 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {{pks: chunk.join(','),apiVersion: args.apiVersion,+ ...(args.args || {}),},{limitOverride: chunk.length,diff --git a/packages/nocodb/src/db/BaseModelSqlv2/add-remove-links.ts b/packages/nocodb/src/db/BaseModelSqlv2/add-remove-links.tsindex 15b0de8b81..24c4c1db97 100644--- a/packages/nocodb/src/db/BaseModelSqlv2/add-remove-links.ts+++ b/packages/nocodb/src/db/BaseModelSqlv2/add-remove-links.ts@@ -16,6 +16,8 @@ import {getRelatedLinksColumn,} from '~/helpers/dbHelpers';import { Model } from '~/models';+import NocoSocket from '~/socket/NocoSocket';+import getAst from '~/helpers/getAst';export const addOrRemoveLinks = (baseModel: IBaseModelSqlV2) => {const validateRefIds = (@@ -278,12 +280,16 @@ export const addOrRemoveLinks = (baseModel: IBaseModelSqlV2) => {cookie,});+ await broadcastLinkUpdates(parentBaseModel, childIds as string[]);+await childBaseModel.updateLastModified({model: childTable,rowIds: [rowId],cookie,});+ await broadcastLinkUpdates(childBaseModel, [rowId]);+auditConfig.parentModel =baseModel.model.id === parentTable.id ? parentTable : childTable;auditConfig.childModel =@@ -370,6 +376,8 @@ export const addOrRemoveLinks = (baseModel: IBaseModelSqlV2) => {rowIds: [rowId],cookie,});++ await broadcastLinkUpdates(parentBaseModel, [rowId]);}break;case RelationTypes.BELONGS_TO:@@ -424,6 +432,7 @@ export const addOrRemoveLinks = (baseModel: IBaseModelSqlV2) => {rowIds: [rowId],cookie,});+ await broadcastLinkUpdates(parentBaseModel, [rowId]);}break;}@@ -681,12 +690,17 @@ export const addOrRemoveLinks = (baseModel: IBaseModelSqlV2) => {rowIds: childIds,cookie,});++ await broadcastLinkUpdates(parentBaseModel, childIds as string[]);+await childBaseModel.updateLastModified({model: childTable,rowIds: [rowId],cookie,});+ await broadcastLinkUpdates(childBaseModel, [rowId]);+auditConfig.parentModel =baseModel.model.id === parentTable.id ? parentTable : childTable;auditConfig.childModel =@@ -779,6 +793,8 @@ export const addOrRemoveLinks = (baseModel: IBaseModelSqlV2) => {rowIds: [rowId],cookie,});++ await broadcastLinkUpdates(parentBaseModel, [rowId]);}break;case RelationTypes.BELONGS_TO:@@ -836,6 +852,8 @@ export const addOrRemoveLinks = (baseModel: IBaseModelSqlV2) => {rowIds: [childIds[0]],cookie,});++ await broadcastLinkUpdates(parentBaseModel, [childIds[0] as string]);}break;}@@ -894,8 +912,38 @@ export const addOrRemoveLinks = (baseModel: IBaseModelSqlV2) => {childAuditObj,);};++ const broadcastLinkUpdates = async (+ baseModel: IBaseModelSqlV2,+ ids: Array<string>,+ ) => {+ try {+ const ast = await getAst(baseModel.context, {+ model: baseModel.model,+ });++ const list = await baseModel.chunkList({+ pks: ids,+ chunkSize: 100,+ args: ast.dependencyFields,+ });++ for (const item of list) {+ const extractedId = baseModel.extractPksValues(item);+ NocoSocket.broadcastDataEvent(baseModel.context, baseModel.model.id, {+ action: 'update',+ payload: item,+ id: extractedId,+ });+ }+ } catch (e) {+ console.error(e);+ }+ };+return {addLinks,+ broadcastLinkUpdates,removeLinks,};};diff --git a/packages/nocodb/src/db/IBaseModelSqlV2.ts b/packages/nocodb/src/db/IBaseModelSqlV2.tsindex 5f223e41c9..dff99f6915 100644--- a/packages/nocodb/src/db/IBaseModelSqlV2.ts+++ b/packages/nocodb/src/db/IBaseModelSqlV2.ts@@ -13,9 +13,9 @@ import type {PermissionKey,RelationTypes,} from 'nocodb-sdk';-import type { Column, Model, View } from '~/models';import type { Knex } from 'knex';import type CustomKnex from '~/db/CustomKnex';+import type { Column, Model, Source, View } from '~/models';export interface IBaseModelSqlV2 {context: NcContext;@@ -296,6 +296,13 @@ export interface IBaseModelSqlV2 {req: any;}): Promise<void>;+ chunkList(args: {+ pks: string[];+ chunkSize?: number;+ apiVersion?: NcApiVersion;+ args?: any;+ }): Promise<any[]>;+get viewId(): string;get dbDriver(): CustomKnex;get isSqlite(): boolean;diff --git a/packages/nocodb/src/db/relation-manager.ts b/packages/nocodb/src/db/relation-manager.tsindex 2240734d01..1fa2f496c0 100644--- a/packages/nocodb/src/db/relation-manager.ts+++ b/packages/nocodb/src/db/relation-manager.ts@@ -11,6 +11,8 @@ import {getCompositePkValue,getOppositeRelationType,} from '~/helpers/dbHelpers';+import NocoSocket from '~/ee/socket/NocoSocket';+import getAst from '~/helpers/getAst';interface AuditUpdateLog {pkValue?: Record<string, any>;@@ -291,12 +293,17 @@ export class RelationManager {rowIds: [parentId],cookie: req,});++ await this.broadcastLinkUpdates(parentBaseModel, [parentId]);+await childBaseModel.updateLastModified({baseModel: childBaseModel,model: childTable,rowIds: [childId],cookie: req,});++ await this.broadcastLinkUpdates(childBaseModel, [childId]);}break;case RelationTypes.HAS_MANY:@@ -368,12 +375,16 @@ export class RelationManager {cookie: req,});+ await this.broadcastLinkUpdates(childBaseModel, [childId]);+await parentBaseModel.updateLastModified({baseModel: parentBaseModel,model: parentTable,rowIds: [parentId],cookie: req,});++ await this.broadcastLinkUpdates(parentBaseModel, [parentId]);}break;case RelationTypes.BELONGS_TO:@@ -410,6 +421,7 @@ export class RelationManager {direction: 'child_parent',type: getOppositeRelationType(colOptions.type),});+await parentBaseModel.updateLastModified({baseModel: parentBaseModel,model: parentTable,@@ -444,12 +456,16 @@ export class RelationManager {cookie: req,});+ await this.broadcastLinkUpdates(childBaseModel, [childId]);+await parentBaseModel.updateLastModified({baseModel: parentBaseModel,model: parentTable,rowIds: [parentId],cookie: req,});++ await this.broadcastLinkUpdates(parentBaseModel, [parentId]);}break;case RelationTypes.ONE_TO_ONE:@@ -584,12 +600,17 @@ export class RelationManager {rowIds: [childId],cookie: req,});++ await this.broadcastLinkUpdates(childBaseModel, [childId]);+await parentBaseModel.updateLastModified({baseModel: parentBaseModel,model: parentTable,rowIds: parentId,cookie: req,});++ await this.broadcastLinkUpdates(parentBaseModel, [parentId]);}break;}@@ -683,12 +704,17 @@ export class RelationManager {rowIds: [parentId],cookie: req,});++ await this.broadcastLinkUpdates(parentBaseModel, [parentId]);+await childBaseModel.updateLastModified({baseModel: childBaseModel,model: childTable,rowIds: [childId],cookie: req,});++ await this.broadcastLinkUpdates(childBaseModel, [childId]);}break;case RelationTypes.HAS_MANY:@@ -713,12 +739,17 @@ export class RelationManager {rowIds: [childId],cookie: req,});++ await this.broadcastLinkUpdates(childBaseModel, [childId]);+await parentBaseModel.updateLastModified({baseModel: parentBaseModel,model: parentTable,rowIds: [parentId],cookie: req,});++ await this.broadcastLinkUpdates(parentBaseModel, [parentId]);}break;case RelationTypes.BELONGS_TO:@@ -744,12 +775,17 @@ export class RelationManager {rowIds: [childId],cookie: req,});++ await this.broadcastLinkUpdates(childBaseModel, [childId]);+await parentBaseModel.updateLastModified({baseModel: parentBaseModel,model: parentTable,- rowIds: [childId],+ rowIds: [parentId],cookie: req,});++ await this.broadcastLinkUpdates(parentBaseModel, [parentId]);}break;case RelationTypes.ONE_TO_ONE:@@ -769,12 +805,16 @@ export class RelationManager {rowIds: [childId],cookie: req,});++ await this.broadcastLinkUpdates(childBaseModel, [childId]);+await parentBaseModel.updateLastModified({baseModel: parentBaseModel,model: parentTable,- rowIds: [childId],+ rowIds: [parentId],cookie: req,});+ await this.broadcastLinkUpdates(parentBaseModel, [parentId]);}break;}@@ -872,4 +912,29 @@ export class RelationManager {} as AuditUpdateObj;});}++ async broadcastLinkUpdates(baseModel: IBaseModelSqlV2, ids: Array<string>) {+ try {+ const ast = await getAst(baseModel.context, {+ model: baseModel.model,+ });++ const list = await baseModel.chunkList({+ pks: ids,+ chunkSize: 100,+ args: ast.dependencyFields,+ });++ for (const item of list) {+ const extractedId = baseModel.extractPksValues(item);+ NocoSocket.broadcastDataEvent(baseModel.context, baseModel.model.id, {+ action: 'update',+ payload: item,+ id: extractedId,+ });+ }+ } catch (e) {+ console.error(e);+ }+ }}