Skip to content

Commit

Permalink
🐝 fix eslint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Mar 15, 2024
1 parent 42b46b0 commit d983d4b
Show file tree
Hide file tree
Showing 29 changed files with 16 additions and 57 deletions.
6 changes: 1 addition & 5 deletions adminSiteServer/apiRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from "../settings/serverSettings.js"
import { expectInt, isValidSlug } from "../serverUtils/serverUtil.js"
import { OldChart, Chart, getGrapherById } from "../db/model/Chart.js"
import { Request, Response, CurrentUser } from "./authentication.js"
import { Request, CurrentUser } from "./authentication.js"
import {
getMergedGrapherConfigForVariable,
fetchS3MetadataByPath,
Expand All @@ -36,7 +36,6 @@ import {
OwidGdocPostInterface,
parseIntOrUndefined,
parseToOperation,
DbEnrichedPost,
DbRawPostWithGdocPublishStatus,
SuggestedChartRevisionStatus,
variableAnnotationAllowedColumnNamesAndTypes,
Expand All @@ -60,7 +59,6 @@ import {
DbRawVariable,
DbRawOrigin,
parseOriginsRow,
AnalyticsPageviewsTableName,
PostsTableName,
DbRawPost,
} from "@ourworldindata/types"
Expand Down Expand Up @@ -102,11 +100,9 @@ import { Link } from "../db/model/Link.js"
import { In } from "typeorm"
import { logErrorAndMaybeSendToBugsnag } from "../serverUtils/errorLog.js"
import { GdocFactory } from "../db/model/Gdoc/GdocFactory.js"
import { Knex } from "knex"
import {
getRouteWithROTransaction,
deleteRouteWithRWTransaction,
patchRouteWithRWTransaction,
putRouteWithRWTransaction,
postRouteWithRWTransaction,
} from "./routerHelpers.js"
Expand Down
1 change: 0 additions & 1 deletion adminSiteServer/gitDataExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import filenamify from "filenamify"
import { execFormatted } from "../db/execWrapper.js"
import { JsonError } from "@ourworldindata/utils"
import { DbPlainDataset } from "@ourworldindata/types"
import { Knex } from "knex"
import { getSourcesForDataset } from "../db/model/Source.js"

const datasetToReadme = async (
Expand Down
2 changes: 1 addition & 1 deletion adminSiteServer/routerHelpers.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FunctionalRouter } from "./FunctionalRouter.js"
import { IRouter, Request, Response, Router } from "express"
import { Request, Response } from "express"
import * as db from "../db/db.js"
export function getRouteWithROTransaction<T>(
router: FunctionalRouter,
Expand Down
1 change: 0 additions & 1 deletion baker/DeployUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
import { SiteBaker } from "../baker/SiteBaker.js"
import { WebClient } from "@slack/web-api"
import { DeployChange, DeployMetadata } from "@ourworldindata/utils"
import { Knex } from "knex"
import { KnexReadonlyTransaction } from "../db/db.js"

const deployQueueServer = new DeployQueueServer()
Expand Down
1 change: 0 additions & 1 deletion baker/ExplorerBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { explorerUrlMigrationsById } from "../explorer/urlMigrations/ExplorerUrl
import { ExplorerAdminServer } from "../explorerAdminServer/ExplorerAdminServer.js"
import { explorerRedirectTable } from "../explorerAdminServer/ExplorerRedirects.js"
import { renderExplorerPage } from "./siteRenderers.js"
import { Knex } from "knex"
import * as db from "../db/db.js"

export const bakeAllPublishedExplorers = async (
Expand Down
1 change: 0 additions & 1 deletion baker/GrapherBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import { parseFaqs } from "../db/model/Gdoc/rawToEnriched.js"
import { GdocPost } from "../db/model/Gdoc/GdocPost.js"
import { getShortPageCitation } from "../site/gdocs/utils.js"
import { getSlugForTopicTag, getTagToSlugMap } from "./GrapherBakingUtils.js"
import { Knex } from "knex"
import { knexRaw } from "../db/db.js"
import { getRelatedChartsForVariable } from "../db/model/Chart.js"
import pMap from "p-map"
Expand Down
1 change: 0 additions & 1 deletion baker/SiteBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ import {
getVariableMetadata,
getVariableOfDatapageIfApplicable,
} from "../db/model/Variable.js"
import { Knex } from "knex"
import { getBakePath } from "@ourworldindata/components"
import { GdocAuthor } from "../db/model/Gdoc/GdocAuthor.js"

Expand Down
1 change: 0 additions & 1 deletion baker/algolia/indexChartsToAlgolia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { MarkdownTextWrap } from "@ourworldindata/components"
import { getAnalyticsPageviewsByUrlObj } from "../../db/model/Pageview.js"
import { Link } from "../../db/model/Link.js"
import { getRelatedArticles } from "../../db/model/Post.js"
import { Knex } from "knex"

const computeScore = (record: Omit<ChartRecord, "score">): number => {
const { numRelatedArticles, views_7d } = record
Expand Down
1 change: 0 additions & 1 deletion baker/algolia/indexExplorersToAlgolia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { getAnalyticsPageviewsByUrlObj } from "../../db/model/Pageview.js"
import { chunkParagraphs } from "../chunk.js"
import { SearchIndexName } from "../../site/search/searchTypes.js"
import { Chart } from "../../db/model/Chart.js"
import { Knex } from "knex"

type ExplorerBlockColumns = {
type: "columns"
Expand Down
1 change: 0 additions & 1 deletion baker/algolia/indexToAlgolia.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
getPostTags,
getPostsFromSnapshots,
} from "../../db/model/Post.js"
import { Knex } from "knex"

interface TypeAndImportance {
type: PageType
Expand Down
1 change: 0 additions & 1 deletion baker/countryProfiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { countries, getCountryBySlug, JsonError } from "@ourworldindata/utils"
import { renderToHtmlPage } from "./siteRenderers.js"
import { dataAsDF } from "../db/model/Variable.js"
import pl from "nodejs-polars"
import knex from "knex"

export const countriesIndexPage = (baseUrl: string) =>
renderToHtmlPage(
Expand Down
1 change: 0 additions & 1 deletion baker/formatWordpressPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import { renderKeyInsights, renderProminentLinks } from "./siteRenderers.js"
import { KEY_INSIGHTS_CLASS_NAME } from "../site/blocks/KeyInsights.js"
import { RELATED_CHARTS_CLASS_NAME } from "../site/blocks/RelatedCharts.js"
import { logErrorAndMaybeSendToBugsnag } from "../serverUtils/errorLog.js"
import { Knex } from "knex"
import { KnexReadonlyTransaction } from "../db/db.js"

const initMathJax = () => {
Expand Down
1 change: 0 additions & 1 deletion baker/postUpdatedHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
getPostLinksBySourceId,
insertManyPostLinks,
} from "../db/model/PostLink.js"
import { Knex } from "knex"
const argv = parseArgs(process.argv.slice(2))

const zeroDateString = "0000-00-00 00:00:00"
Expand Down
5 changes: 1 addition & 4 deletions baker/redirects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import * as redirects from "./redirects.js"
import { resolveInternalRedirect } from "./redirects.js"

import { jest } from "@jest/globals"
import { Knex } from "knex"
import { KnexReadonlyTransaction, knexReadonlyTransaction } from "../db/db.js"
import { KnexReadonlyTransaction } from "../db/db.js"

type ArrayForMap = [string, string][]

Expand All @@ -18,8 +17,6 @@ const getFormattedUrl = (url: string): Url => {
return Url.fromURL(formatUrls(url))
}

const knex: Knex = {} as Knex

it("resolves pathnames", async () => {
const src = "/hello"
const target = "/world"
Expand Down
1 change: 0 additions & 1 deletion baker/redirects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { isCanonicalInternalUrl } from "./formatting.js"
import { resolveExplorerRedirect } from "./replaceExplorerRedirects.js"
import { logErrorAndMaybeSendToBugsnag } from "../serverUtils/errorLog.js"
import { getRedirectsFromDb } from "../db/model/Redirect.js"
import { Knex } from "knex"

export const getRedirects = async (knex: db.KnexReadonlyTransaction) => {
const staticRedirects = [
Expand Down
1 change: 0 additions & 1 deletion baker/siteRenderers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import {} from "../site/blocks/ProminentLink.js"
import { renderExplorerPage } from "./siteRenderers.js"
import { ExplorerProgram } from "../explorer/ExplorerProgram.js"
import { Knex } from "knex"
import { KnexReadonlyTransaction } from "../db/db.js"

// Note: renderProminentLinks() tests are now e2e (see kitchenSink.js)
Expand Down
1 change: 0 additions & 1 deletion baker/siteRenderers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ import { GdocPost } from "../db/model/Gdoc/GdocPost.js"
import { logErrorAndMaybeSendToBugsnag } from "../serverUtils/errorLog.js"
import { GdocFactory } from "../db/model/Gdoc/GdocFactory.js"
import { SiteNavigationStatic } from "../site/SiteNavigation.js"
import { Knex } from "knex"

export const renderToHtmlPage = (element: any) =>
`<!doctype html>${ReactDOMServer.renderToStaticMarkup(element)}`
Expand Down
1 change: 0 additions & 1 deletion baker/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { EXPLORERS_ROUTE_FOLDER } from "../explorer/ExplorerConstants.js"
import { ExplorerProgram } from "../explorer/ExplorerProgram.js"
import { GdocPost } from "../db/model/Gdoc/GdocPost.js"
import { getPostsFromSnapshots } from "../db/model/Post.js"
import { Knex } from "knex"
import { calculateDataInsightIndexPageCount } from "../db/model/Gdoc/gdocUtils.js"

interface SitemapUrl {
Expand Down
6 changes: 0 additions & 6 deletions db/model/Chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
BAKED_BASE_URL,
OPENAI_API_KEY,
} from "../../settings/serverSettings.js"
import { Knex } from "knex"

// XXX hardcoded filtering to public parent tags
export const PUBLIC_TAG_PARENT_IDS = [
Expand Down Expand Up @@ -260,11 +259,6 @@ WHERE c.config -> "$.isPublished" = true
}
}

interface ChartRow {
id: number
config: any
}

// TODO integrate this old logic with typeorm
export class OldChart {
static listFields = `
Expand Down
1 change: 0 additions & 1 deletion db/model/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
VariablesTableName,
DbRawVariable,
} from "@ourworldindata/types"
import { Knex } from "knex"

@Entity("datasets")
@Unique(["name", "namespace"])
Expand Down
1 change: 0 additions & 1 deletion db/model/Pageview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { keyBy } from "lodash"
import { Entity, Column, BaseEntity } from "typeorm"
import { RawPageview } from "@ourworldindata/utils"
import * as db from "../db.js"
import { Knex } from "knex"
import {
DbPlainAnalyticsPageview,
AnalyticsPageviewsTableName,
Expand Down
1 change: 0 additions & 1 deletion db/model/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { GdocPost } from "./Gdoc/GdocPost.js"
import { SiteNavigationStatic } from "../../site/SiteNavigation.js"
import { decodeHTML } from "entities"
import { RelatedResearchQueryResult } from "../wpdb"
import { number } from "prop-types"

export const postsTable = "posts"

Expand Down
1 change: 0 additions & 1 deletion db/model/PostLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
Url,
} from "@ourworldindata/utils"
import { getLinkType, getUrlTarget } from "@ourworldindata/components"
import { Knex } from "knex"
import { KnexReadWriteTransaction, KnexReadonlyTransaction } from "../db.js"
export function postLinkCreateFromUrl({
url,
Expand Down
1 change: 0 additions & 1 deletion db/model/Redirect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Knex } from "knex"
import { DbPlainRedirect } from "@ourworldindata/types"
import * as db from "../db"

Expand Down
1 change: 0 additions & 1 deletion db/model/Source.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Entity, PrimaryGeneratedColumn, Column, BaseEntity } from "typeorm"
import { Knex } from "knex"
import {
DbEnrichedSource,
DbRawSource,
Expand Down
1 change: 0 additions & 1 deletion db/model/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
DbInsertUser,
UsersTableName,
} from "@ourworldindata/types"
import { Knex } from "knex"
import { KnexReadWriteTransaction, KnexReadonlyTransaction } from "../db.js"

@Entity("users")
Expand Down
1 change: 0 additions & 1 deletion db/model/Variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
OwidProcessingLevel,
DbRawVariable,
} from "@ourworldindata/types"
import { Knex } from "knex/types"
import { knexRaw, knexRawFirst } from "../db.js"

export interface VariableRow {
Expand Down
1 change: 0 additions & 1 deletion db/refreshPageviewsFromDatasette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Papa from "papaparse"
import * as db from "./db.js"
import { DbPlainAnalyticsPageview } from "@ourworldindata/types"
import { omitUndefinedValues } from "@ourworldindata/utils"
import { Knex } from "knex"

const analyticsPageviewsColumnNames: Array<keyof DbPlainAnalyticsPageview> = [
"day",
Expand Down
30 changes: 13 additions & 17 deletions db/syncPostsToGrapher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
} from "./model/PostLink.js"
import { renderTablePress } from "../site/Tablepress.js"
import pMap from "p-map"
import { Knex } from "knex"

const zeroDateString = "0000-00-00 00:00:00"

Expand Down Expand Up @@ -333,9 +332,7 @@ const syncPostsToGrapher = async (
)

const doesExistInWordpress = keyBy(rows, "ID")
const existsInGrapher = await select("id").from(
knex.from(postsTable)
)
const existsInGrapher = await select("id").from(knex.from(postsTable))
const doesExistInGrapher = keyBy(existsInGrapher, "id")

const toDelete = existsInGrapher
Expand Down Expand Up @@ -408,19 +405,18 @@ const syncPostsToGrapher = async (
linksToDelete.push(...linksToModify.linksToDelete)
}


if (toDelete.length)
await knex.whereIn("id", toDelete).delete().from(postsTable)

for (const row of toInsert) {
const rowForDb = serializePostRow(row)
if (doesExistInGrapher[row.id])
await knex
.update(rowForDb)
.where("id", "=", rowForDb.id)
.into(postsTable)
else await knex.insert(rowForDb).into(postsTable)
}
if (toDelete.length)
await knex.whereIn("id", toDelete).delete().from(postsTable)

for (const row of toInsert) {
const rowForDb = serializePostRow(row)
if (doesExistInGrapher[row.id])
await knex
.update(rowForDb)
.where("id", "=", rowForDb.id)
.into(postsTable)
else await knex.insert(rowForDb).into(postsTable)
}

// TODO: unify our DB access and then do everything in one transaction
if (linksToAdd.length) {
Expand Down

0 comments on commit d983d4b

Please sign in to comment.