From 52332f1f5f02c0f2a9a7bda7f4d67d0c63fed87d Mon Sep 17 00:00:00 2001 From: Matthieu Bergel Date: Sat, 11 May 2024 14:12:50 +0000 Subject: [PATCH] fix(gdoc): insert subclass enriched version in DB --- db/model/Gdoc/GdocFactory.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/db/model/Gdoc/GdocFactory.ts b/db/model/Gdoc/GdocFactory.ts index 86e9c94451f..584580d6530 100644 --- a/db/model/Gdoc/GdocFactory.ts +++ b/db/model/Gdoc/GdocFactory.ts @@ -97,7 +97,6 @@ export async function createGdocAndInsertIntoDb( // We have to fetch it here because we need to know the type of the Gdoc in load() const base = new GdocBase(id) await base.fetchAndEnrichGdoc() - await upsertGdoc(knex, base) // Load its metadata and state so that subclass parsing & validation is also done. // This involves a second call to the DB and Google, which makes me sad, but it'll do for now. @@ -107,8 +106,13 @@ export async function createGdocAndInsertIntoDb( GdocsContentSource.Gdocs ) - // 2024-03-12 Daniel: We used to save here before the knex refactor but I think that was redundant? - // await gdoc.save() + // Save the enriched Gdoc to the database (including subclass-specific + // enrichments, cf. _enrichSubclassContent()). Otherwise subclass + // enrichments are not present on the Gdoc subclass when loading from the DB + // (GdocsContentSource.Internal), since subclass enrichements are only done + // while fetching the live gdocs (GdocsContentSource.Gdocs) in + // loadFromGdocBase(). + await upsertGdoc(knex, gdoc) return gdoc }