|
1 | 1 | import { SourceControlProviderKind } from "@t3tools/contracts"; |
2 | | -import * as Cache from "effect/Cache"; |
3 | 2 | import * as Effect from "effect/Effect"; |
4 | 3 | import * as Schema from "effect/Schema"; |
5 | 4 | import * as Result from "effect/Result"; |
@@ -149,51 +148,20 @@ export const make = Effect.gen(function* () { |
149 | 148 | } |
150 | 149 | return { items, truncated: true }; |
151 | 150 | }); |
152 | | - // Share pending reads only: credentials and repository permissions can change between requests. |
153 | | - const cacheKey = (...parts: ReadonlyArray<string | number | undefined>) => |
154 | | - parts.map((part) => encodeURIComponent(String(part ?? ""))).join("\n"); |
155 | | - const pulls = yield* Cache.makeWith( |
156 | | - (key: string) => { |
157 | | - const [cwd = "", repository = "", host = "", number = ""] = key |
158 | | - .split("\n") |
159 | | - .map(decodeURIComponent); |
160 | | - const ref = { cwd, repository, host, number: Number(number) }; |
161 | | - return read({ ...ref, path: pullPath(ref) }, ForgejoPullRequest); |
162 | | - }, |
163 | | - { capacity: 64, timeToLive: () => 0 }, |
164 | | - ); |
| 151 | + // These reads select the current account independently of older pending requests. |
165 | 152 | const getPull = (input: ProviderRepositoryRef & { readonly number: number }) => |
166 | | - Cache.get(pulls, cacheKey(input.cwd, input.repository, input.host, input.number)); |
167 | | - const write = (input: ForgejoCli.ForgejoApiInput) => |
168 | | - request(input).pipe( |
169 | | - Effect.onExit(() => Cache.invalidateAll(pulls)), |
170 | | - Effect.asVoid, |
| 153 | + read( |
| 154 | + { cwd: input.cwd, repository: input.repository, host: input.host, path: pullPath(input) }, |
| 155 | + ForgejoPullRequest, |
171 | 156 | ); |
172 | | - const repos = yield* Cache.makeWith( |
173 | | - (key: string) => { |
174 | | - const [cwd = "", repository = "", host = ""] = key.split("\n").map(decodeURIComponent); |
175 | | - const ref = { cwd, repository, host }; |
176 | | - return read({ ...ref, path: repoPath(ref) }, ForgejoRepository); |
177 | | - }, |
178 | | - { capacity: 32, timeToLive: () => 0 }, |
179 | | - ); |
180 | | - const viewers = yield* Cache.makeWith( |
181 | | - (key: string) => { |
182 | | - const [cwd = "", repository, host] = key.split("\n").map(decodeURIComponent); |
183 | | - return read( |
184 | | - { cwd, ...(repository ? { repository } : {}), ...(host ? { host } : {}), path: "user" }, |
185 | | - ForgejoUser, |
186 | | - ).pipe(Effect.map((user) => user.login)); |
187 | | - }, |
188 | | - { capacity: 32, timeToLive: () => 0 }, |
189 | | - ); |
| 157 | + const write = (input: ForgejoCli.ForgejoApiInput) => request(input).pipe(Effect.asVoid); |
190 | 158 | const getRepo = (input: ProviderRepositoryRef) => |
191 | | - Cache.get(repos, cacheKey(input.cwd, input.repository, input.host)); |
| 159 | + read({ ...input, path: repoPath(input) }, ForgejoRepository); |
192 | 160 | const getViewer = (input: { |
193 | 161 | readonly cwd: string; |
194 | 162 | readonly repository?: string; |
195 | 163 | readonly host?: string; |
196 | | - }) => Cache.get(viewers, cacheKey(input.cwd, input.repository, input.host)); |
| 164 | + }) => read({ ...input, path: "user" }, ForgejoUser).pipe(Effect.map((user) => user.login)); |
197 | 165 | const permissions = ( |
198 | 166 | repo: typeof ForgejoRepository.Type, |
199 | 167 | pr: typeof ForgejoPullRequest.Type, |
@@ -224,14 +192,8 @@ export const make = Effect.gen(function* () { |
224 | 192 | const getPermissions = Effect.fn("ForgejoPullRequestProvider.getPermissions")(function* ( |
225 | 193 | input: ProviderRepositoryRef & { readonly number: number }, |
226 | 194 | ) { |
227 | | - // A write must not join a detail read started before the account or access changed. |
228 | | - const fresh = { ...input, freshCredentials: true }; |
229 | 195 | const [repo, pr, viewer] = yield* Effect.all( |
230 | | - [ |
231 | | - read({ ...fresh, path: repoPath(input) }, ForgejoRepository), |
232 | | - read({ ...fresh, path: pullPath(input) }, ForgejoPullRequest), |
233 | | - read({ ...fresh, path: "user" }, ForgejoUser).pipe(Effect.map((user) => user.login)), |
234 | | - ], |
| 196 | + [getRepo(input), getPull(input), getViewer(input)], |
235 | 197 | { concurrency: 3 }, |
236 | 198 | ); |
237 | 199 | return permissions(repo, pr, viewer); |
@@ -515,16 +477,7 @@ export const make = Effect.gen(function* () { |
515 | 477 | body: { body: input.body }, |
516 | 478 | }), |
517 | 479 | submitReview: Effect.fn("ForgejoPullRequestProvider.submitReview")(function* (input) { |
518 | | - const pr = yield* read( |
519 | | - { |
520 | | - cwd: input.cwd, |
521 | | - repository: input.repository, |
522 | | - host: input.host, |
523 | | - path: pullPath(input), |
524 | | - freshCredentials: true, |
525 | | - }, |
526 | | - ForgejoPullRequest, |
527 | | - ); |
| 480 | + const pr = yield* getPull(input); |
528 | 481 | yield* write({ |
529 | 482 | ...input, |
530 | 483 | path: `${pullPath(input)}/reviews`, |
|
0 commit comments