Skip to content

Commit

Permalink
Remove knowledge of the HTTP cache
Browse files Browse the repository at this point in the history
Refs #1834, #2186
  • Loading branch information
thewilkybarkid committed Mar 4, 2025
1 parent 60868a0 commit bb194a5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
9 changes: 7 additions & 2 deletions src/OpenAlex/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import type * as Doi from 'doi-ts'
import { Effect, pipe } from 'effect'
import { getCategories, getWorkByDoi, WorkIsUnavailable } from './Work.js'
import { Context, Effect, pipe } from 'effect'
import { getCategories, getWorkByDoi, type WorkIsNotFound, WorkIsUnavailable } from './Work.js'

export class GetCategories extends Context.Tag('GetCategories')<
GetCategories,
(doi: Doi.Doi) => Effect.Effect<ReadonlyArray<{ id: URL; display_name: string }>, WorkIsNotFound | WorkIsUnavailable>
>() {}

export const getCategoriesFromOpenAlex = (doi: Doi.Doi) =>
pipe(
Expand Down
11 changes: 11 additions & 0 deletions src/Program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { getPseudonymFromLegacyPrereview } from './legacy-prereview.js'
import * as LibsqlEventStore from './LibsqlEventStore.js'
import { DefaultLocale, translate } from './locales/index.js'
import { Nodemailer, sendEmailWithNodemailer } from './nodemailer.js'
import * as OpenAlex from './OpenAlex/index.js'
import { getNameFromOrcid } from './orcid.js'
import * as Preprint from './preprint.js'
import * as Prereview from './Prereview.js'
Expand Down Expand Up @@ -314,6 +315,15 @@ const getPreprint = Layer.effect(
}),
)

const getCategories = Layer.effect(
OpenAlex.GetCategories,
Effect.gen(function* () {
const httpClient = yield* HttpClient.HttpClient

return id => pipe(OpenAlex.getCategoriesFromOpenAlex(id), Effect.provideService(HttpClient.HttpClient, httpClient))
}),
)

const setUpFetch = Layer.effect(
FetchHttpClient.Fetch,
Effect.gen(function* () {
Expand All @@ -336,6 +346,7 @@ export const Program = pipe(
Layer.provide(
Layer.mergeAll(
Layer.provide(getPreprint, CachingHttpClient.layer('10 minutes')),
Layer.provide(getCategories, CachingHttpClient.layer('10 minutes')),
doesUserHaveAVerifiedEmailAddress,
getContactEmailAddress,
saveContactEmailAddress,
Expand Down
11 changes: 3 additions & 8 deletions src/app-router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { HttpClient } from '@effect/platform'
import cookieSignature from 'cookie-signature'
import { Effect, Function, Option, String, flow, pipe } from 'effect'
import * as P from 'fp-ts-routing'
Expand All @@ -21,13 +20,12 @@ import multer, { MulterError } from 'multer'
import type { Orcid } from 'orcid-id-ts'
import { match } from 'ts-pattern'
import type { ZenodoAuthenticatedEnv } from 'zenodo-ts'
import * as CachingHttpClient from './CachingHttpClient/index.js'
import type { Locale } from './Context.js'
import type { EffectEnv } from './EffectToFpts.js'
import * as EffectToFpts from './EffectToFpts.js'
import { withEnv } from './Fpts.js'
import type { GetPageFromGhostEnv } from './GhostPage.js'
import { getCategoriesFromOpenAlex } from './OpenAlex/index.js'
import * as OpenAlex from './OpenAlex/index.js'
import {
authorInvite,
authorInviteCheck,
Expand Down Expand Up @@ -334,7 +332,7 @@ const getSlackUser = flow(
export type RouterEnv = Keyv.AvatarStoreEnv &
MustDeclareUseOfAiEnv &
DoesPreprintExistEnv &
EffectEnv<Locale | HttpClient.HttpClient | CachingHttpClient.HttpCache> &
EffectEnv<Locale | OpenAlex.GetCategories> &
ResolvePreprintIdEnv &
GetPageFromGhostEnv &
GetPreprintIdEnv &
Expand Down Expand Up @@ -1611,10 +1609,7 @@ const router: P.Parser<RM.ReaderMiddleware<RouterEnv, StatusOpen, ResponseEnded,
.with({ type: 'philsci' }, () => RTE.of([]))
.otherwise(
EffectToFpts.toReaderTaskEitherK(id =>
pipe(
getCategoriesFromOpenAlex(id.value),
Effect.provide(CachingHttpClient.layer('10 minutes')),
),
pipe(OpenAlex.GetCategories, Effect.andThen(Function.apply(id.value))),
),
),
RTE.match(
Expand Down

0 comments on commit bb194a5

Please sign in to comment.