diff --git a/connectors/src/connectors/notion/temporal/activities.ts b/connectors/src/connectors/notion/temporal/activities.ts index d96c74b73f11..16a4e7a0d51d 100644 --- a/connectors/src/connectors/notion/temporal/activities.ts +++ b/connectors/src/connectors/notion/temporal/activities.ts @@ -32,7 +32,10 @@ import { updateAllParentsFields, } from "@connectors/connectors/notion/lib/parents"; import { getTagsForPage } from "@connectors/connectors/notion/lib/tags"; -import { ParsedNotionBlock } from "@connectors/connectors/notion/lib/types"; +import { + PageObjectProperties, + ParsedNotionBlock, +} from "@connectors/connectors/notion/lib/types"; import { deleteFromDataSource, MAX_DOCUMENT_TXT_LEN, @@ -1019,7 +1022,8 @@ export async function cachePage({ await NotionConnectorPageCacheEntry.create({ notionPageId: pageId, connectorId: connector.id, - pageProperties: notionPage.properties, + pageProperties: {}, + pagePropertiesText: JSON.stringify(notionPage.properties), parentType: parent.type, parentId: parent.id, createdById: notionPage.created_by.id, @@ -1263,7 +1267,8 @@ export async function cacheDatabaseChildren({ NotionConnectorPageCacheEntry.create({ notionPageId: page.id, connectorId: connector.id, - pageProperties: page.properties, + pageProperties: {}, + pagePropertiesText: JSON.stringify(page.properties), parentId: databaseId, parentType: "database", createdById: page.created_by.id, @@ -1380,13 +1385,17 @@ export async function renderAndUpsertPageFromCache({ for (const [databaseId, pages] of Object.entries(childDatabases)) { renderedChildDatabases[databaseId] = renderChildDatabaseFromPages({ databaseTitle: childDatabaseTitleById[databaseId] ?? null, - pagesProperties: pages.map((p) => p.pageProperties), + pagesProperties: pages.map( + (p) => JSON.parse(p.pagePropertiesText) as PageObjectProperties + ), }); } localLogger.info("notionRenderAndUpsertPageFromCache: Rendering page."); let renderedPage = ""; - const parsedProperties = parsePageProperties(pageCacheEntry.pageProperties); + const parsedProperties = parsePageProperties( + JSON.parse(pageCacheEntry.pagePropertiesText) as PageObjectProperties + ); for (const p of parsedProperties) { if (!p.text) continue; renderedPage += `$${p.key}: ${p.text}\n`; diff --git a/connectors/src/lib/models.ts b/connectors/src/lib/models.ts index dfa58fd0b0b7..1424cd776a23 100644 --- a/connectors/src/lib/models.ts +++ b/connectors/src/lib/models.ts @@ -667,6 +667,7 @@ export class NotionConnectorPageCacheEntry extends Model< declare notionPageId: string; declare pageProperties: PageObjectProperties; // JSON -- typed but not guaranteed + declare pagePropertiesText: string; declare parentId: string; declare parentType: "database" | "page" | "workspace" | "block" | "unknown"; declare lastEditedById: string; @@ -703,6 +704,11 @@ NotionConnectorPageCacheEntry.init( type: DataTypes.JSONB, allowNull: false, }, + pagePropertiesText: { + type: DataTypes.TEXT, + allowNull: false, + defaultValue: "{}", + }, parentId: { type: DataTypes.STRING, allowNull: true, @@ -816,12 +822,15 @@ NotionConnectorBlockCacheEntry.init( sequelize: sequelize_conn, modelName: "notion_connector_block_cache_entries", indexes: [ - { - fields: ["notionBlockId", "connectorId", "notionPageId"], - unique: true, - }, + // TODO: fix sync issue with this index + // { + // // fields: ["notionBlockId", "connectorId", "notionPageId"], + // // unique: true, + // }, + // { { fields: ["connectorId"] }, { fields: ["parentBlockId"] }, + { fields: ["notionPageId"] }, ], } );