-
-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🚧 remove typeorm annotations from GDocs classes #3299
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
5d00c2b
to
b93390a
Compare
47f72ea
to
b63272c
Compare
b93390a
to
a02c68d
Compare
9253472
to
e33773a
Compare
a02c68d
to
2124f46
Compare
e33773a
to
5dedb67
Compare
2124f46
to
146ea9e
Compare
43f3e8f
to
f7d9953
Compare
b37a219
to
6358087
Compare
c5a2b89
to
0ca18ae
Compare
0ca18ae
to
23dccc3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Phew! That took a while. Mostly nitpicks to be honest. Imagine there are a couple "🙂" at the end of basically every comment 😅
Will QA tomorrow 🙂🙂
@@ -93,6 +95,27 @@ export interface OwidGdocMinimalPostInterface { | |||
"featured-image"?: string // used in prominent links and research & writing block | |||
} | |||
|
|||
export type OwidGdocIndexItem = Pick< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prettier 🤮
const indexItem = extractGdocIndexItem(gdoc) | ||
const gdocToUpdateIndex = this.gdocs.findIndex((g) => g.id === gdoc.id) | ||
if (gdocToUpdateIndex >= 0) this.gdocs[gdocToUpdateIndex] = indexItem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely more correct, but is it ever actually used? Whenever you load the index page it refetches all gdocs anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah probably not but it just seems like the right thing to do - maybe we change the behaviour in the future and then it's nice if this part already does what you would expect.
adminSiteClient/gdocsDeploy.ts
Outdated
@@ -66,6 +67,7 @@ export const checkIsLightningUpdate = ( | |||
published: false, // requires an update of the blog roll | |||
publishedAt: false, // could require an update of the blog roll | |||
slug: false, // requires updating any articles that link to it | |||
markdown: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind putting this above all the false
s ? Keeps it easier to scan I think.
adminSiteServer/apiRouter.ts
Outdated
return b.updatedAt.getTime() - a.updatedAt.getTime() | ||
}) | ||
) | ||
getRouteWithROTransaction(apiRouter, "/gdocs", async (req, res, trx) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't bother me, but adding async
here is unnecessary, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jup, I mechanically replaced some things and the occasionally a superfluous async came in
db/model/Gdoc/GdocFactory.ts
Outdated
knex: KnexReadonlyTransaction, | ||
id: string, | ||
gdoc: OwidGdoc, | ||
markdownContentSource: OwidEnrichedGdocBlock[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a biggie, just floating it for your consideration, but my rule of thumb is once functions get more than 3 parameters (i.e. it becomes complex enough that the name alone probably doesn't fully describe what it does), I strongly consider changing them to a object so that the arguments get descriptive names in usage.
When first reading this code I had no idea what the flattened sources could be for. Jumping to the definition is easy, so whatever, but also sometimes there are arguments that are similar to one another and bugs can happen if you mistakenly put them in the wrong order.
function updateGdocContentOnly({
knex: trx,
id,
gdoc,
markdownContentSource: gdoc.enrichedBlockSources.flat()
})
It also comes in handy when you've got a series of boolean parameters where you might want to rely on defaults like in getGdocBaseObjectById
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah valid point - when looking at it now though I realized that we might as well just extract it inside the function and get rid of the last parameter.
|
||
if (!gdoc) { | ||
if (!gdoc || !("details" in gdoc.content)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe update the error message here too?
db/model/Gdoc/GdocPost.ts
Outdated
static async getListedGdocPosts( | ||
knex: KnexReadonlyTransaction | ||
): Promise<GdocPost[]> { | ||
return getAndLoadListedGdocPosts(knex) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we just remove this and call the function directly?
db/model/Image.ts
Outdated
filename: string | ||
): Promise<Image | undefined> { | ||
const image = await knex | ||
.table("images") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use a variable here if we're using one for all our other tables 🙂
db/model/Link.ts
Outdated
select posts_gdocs_links.*, posts_gdocs.slug as sourceSlug | ||
from posts_gdocs_links |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not worth it to try given the lack of code formatter for SQL in TS, but should we try to maintain a consistent style for our SQL? Uppercase keywords, indentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There actually is one that works for selections - see the message in our slack in the #developers channel
@@ -61,5 +63,6 @@ export function serializePostsGdocsRow(row: DbEnrichedPostGdoc): DbRawPostGdoc { | |||
...row, | |||
content: serializePostGdocContent(row.content), | |||
breadcrumbs: serializePostsGdocsBreadcrumbs(row.breadcrumbs), | |||
published: row.published ? 1 : 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jsyk you can also do Number(row.published)
🙂
Again, the ternary is probably more explicit but I just like sharing little JS special recipes
6358087
to
2b680e3
Compare
23dccc3
to
713d246
Compare
2b680e3
to
887bc31
Compare
bf7385a
to
8c6f6ac
Compare
Haven't found any remaining issues in QA on the tip of this 🙂 |
887bc31
to
1e899ed
Compare
8c6f6ac
to
575b97e
Compare
575b97e
to
86ce847
Compare
1e899ed
to
1a011bc
Compare
eb9cbd7
to
3a05c68
Compare
1a011bc
to
805d56f
Compare
Also remove the `GdocXImage` and `GdocXTag` classes and switches them to knex. Also introduces OwidGdocIndexItem which is a more lightweight representation of a Gdoc that is used in the overview page of the admin.
3a05c68
to
5e0e462
Compare
This PR converts GDocBase and all related classes (including links, images etc) to be fetched via knex. For GDocs, the classes are kept for business logic but the database loading/saving is done via knex and objects.
The main functionality for loading and storing Gdocs has moved to GDocFactory as plain functions.