Skip to content

Commit

Permalink
hotfix: notion store page properties as raw text (#2128)
Browse files Browse the repository at this point in the history
  • Loading branch information
fontanierh authored Oct 13, 2023
1 parent d1bdde6 commit 2d67b02
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
19 changes: 14 additions & 5 deletions connectors/src/connectors/notion/temporal/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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`;
Expand Down
17 changes: 13 additions & 4 deletions connectors/src/lib/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -703,6 +704,11 @@ NotionConnectorPageCacheEntry.init(
type: DataTypes.JSONB,
allowNull: false,
},
pagePropertiesText: {
type: DataTypes.TEXT,
allowNull: false,
defaultValue: "{}",
},
parentId: {
type: DataTypes.STRING,
allowNull: true,
Expand Down Expand Up @@ -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"] },
],
}
);
Expand Down

0 comments on commit 2d67b02

Please sign in to comment.