Skip to content

Commit

Permalink
Revert 5 latest commits
Browse files Browse the repository at this point in the history
This reverts down to commit 85c2912, inclusive.
  • Loading branch information
mlbrgl committed May 9, 2024
1 parent c6d2547 commit 104ca29
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 42 deletions.
26 changes: 1 addition & 25 deletions db/model/Gdoc/GdocAuthor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
DEFAULT_GDOC_FEATURED_IMAGE,
OwidGdocBaseInterface,
excludeNullish,
defaults,
} from "@ourworldindata/utils"
import { GdocBase } from "./GdocBase.js"
import { htmlToEnrichedTextBlock } from "./htmlToEnriched.js"
Expand All @@ -28,30 +27,7 @@ export class GdocAuthor extends GdocBase implements OwidGdocAuthorInterface {

static create(obj: OwidGdocBaseInterface): GdocAuthor {
const gdoc = new GdocAuthor()

// We need to prevent obj methods from overriding GdocAuthor methods.
// This happens when createGdocAndInsertIntoDb() passes a GdocBase
// instance to loadGdocFromGdocBase(), instead of a simple object. In
// this case, simply assigning obj to gdoc would override GdocAuthor
// methods with GdocBase methods, in particular the
// _enrichedSubclassContent. When creating a new author,
// _enrichedSubclassContent would run from the base GdocBase class
// instead of the GdocAuthor subclass, and the socials block would not
// be shaped as an ArchieML block, thus throwing an error.

// A first approach to avoid this would be to use Object.assign(), while
// omitting functions:
// Object.assign(gdoc, omitBy(obj, isFunction))

// However this approach still lets the parent class override properties
// of the subclass, which can be conceptually surprising.

// So instead, we choose to only override the properties and methods
// that are not defined in the subclass. Note that methods are also
// technically overriden if not defined on the subclass, although we can
// ignore it as this is redundant with inheritance mechanisms.
defaults(gdoc, obj)

Object.assign(gdoc, obj)
return gdoc
}
protected typeSpecificFilenames(): string[] {
Expand Down
3 changes: 1 addition & 2 deletions db/model/Gdoc/GdocDataInsight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
OwidGdocMinimalPostInterface,
OwidGdocBaseInterface,
excludeNullish,
defaults,
} from "@ourworldindata/utils"
import { GdocBase } from "./GdocBase.js"
import * as db from "../../../db/db.js"
Expand All @@ -28,7 +27,7 @@ export class GdocDataInsight

static create(obj: OwidGdocBaseInterface): GdocDataInsight {
const gdoc = new GdocDataInsight()
defaults(gdoc, obj) // see GdocAuthor.ts for rationale
Object.assign(gdoc, obj)
return gdoc
}

Expand Down
13 changes: 5 additions & 8 deletions db/model/Gdoc/GdocFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ export async function createGdocAndInsertIntoDb(
knex: KnexReadWriteTransaction,
id: string
): Promise<OwidGdoc> {
// Fetch the data from Google Docs.
// Fetch the data from Google Docs and save it to the database
// 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.
Expand All @@ -105,13 +106,9 @@ export async function createGdocAndInsertIntoDb(
base,
GdocsContentSource.Gdocs
)
// 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)

// 2024-03-12 Daniel: We used to save here before the knex refactor but I think that was redundant?
// await gdoc.save()

return gdoc
}
Expand Down
3 changes: 1 addition & 2 deletions db/model/Gdoc/GdocHomepage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
OwidGdocHomepageInterface,
OwidGdocMinimalPostInterface,
OwidGdocType,
defaults,
} from "@ourworldindata/utils"
import { GdocBase } from "./GdocBase.js"
import * as db from "../../db.js"
Expand All @@ -29,7 +28,7 @@ export class GdocHomepage

static create(obj: OwidGdocBaseInterface): GdocHomepage {
const gdoc = new GdocHomepage()
defaults(gdoc, obj) // see GdocAuthor.ts for rationale
Object.assign(gdoc, obj)
return gdoc
}

Expand Down
3 changes: 1 addition & 2 deletions db/model/Gdoc/GdocPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
OwidGdocMinimalPostInterface,
OwidGdocBaseInterface,
excludeNullish,
defaults,
} from "@ourworldindata/utils"
import { GDOCS_DETAILS_ON_DEMAND_ID } from "../../../settings/serverSettings.js"
import {
Expand All @@ -38,7 +37,7 @@ export class GdocPost extends GdocBase implements OwidGdocPostInterface {
}
static create(obj: OwidGdocBaseInterface): GdocPost {
const gdoc = new GdocPost()
defaults(gdoc, obj) // see GdocAuthor.ts for rationale
Object.assign(gdoc, obj)
return gdoc
}
linkedDocuments: Record<string, OwidGdocMinimalPostInterface> = {}
Expand Down
2 changes: 0 additions & 2 deletions packages/@ourworldindata/utils/src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
compact,
countBy,
debounce,
defaults,
difference,
drop,
dropRightWhile,
Expand Down Expand Up @@ -80,7 +79,6 @@ export {
compact,
countBy,
debounce,
defaults,
difference,
drop,
dropRightWhile,
Expand Down
1 change: 0 additions & 1 deletion packages/@ourworldindata/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ export {
compact,
countBy,
debounce,
defaults,
difference,
drop,
dropRightWhile,
Expand Down

0 comments on commit 104ca29

Please sign in to comment.