Skip to content

Commit

Permalink
refactor: rename cached -> batched file reader
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattjoh committed Aug 28, 2023
1 parent 2640016 commit a35a740
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/next/src/server/dev/next-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import { DevAppPageRouteMatcherProvider } from '../future/route-matcher-provider
import { DevAppRouteRouteMatcherProvider } from '../future/route-matcher-providers/dev/dev-app-route-route-matcher-provider'
import { PagesManifest } from '../../build/webpack/plugins/pages-manifest-plugin'
import { NodeManifestLoader } from '../future/route-matcher-providers/helpers/manifest-loaders/node-manifest-loader'
import { CachedFileReader } from '../future/route-matcher-providers/dev/helpers/file-reader/cached-file-reader'
import { BatchedFileReader } from '../future/route-matcher-providers/dev/helpers/file-reader/batched-file-reader'
import { DefaultFileReader } from '../future/route-matcher-providers/dev/helpers/file-reader/default-file-reader'
import { NextBuildContext } from '../../build/build-context'
import { IncrementalCache } from '../lib/incremental-cache'
Expand Down Expand Up @@ -208,7 +208,7 @@ export default class DevServer extends Server {
this.dir
)
const extensions = this.nextConfig.pageExtensions
const fileReader = new CachedFileReader(new DefaultFileReader())
const fileReader = new BatchedFileReader(new DefaultFileReader())

// If the pages directory is available, then configure those matchers.
if (pagesDir) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CachedFileReader } from './cached-file-reader'
import { BatchedFileReader } from './batched-file-reader'
import { FileReader } from './file-reader'

describe('CachedFileReader', () => {
Expand All @@ -18,7 +18,7 @@ describe('CachedFileReader', () => {
}
}),
}
const cached = new CachedFileReader(reader)
const cached = new BatchedFileReader(reader)

const results = await Promise.all([
cached.read('<root>/pages'),
Expand Down Expand Up @@ -49,7 +49,7 @@ describe('CachedFileReader', () => {
}
}),
}
const cached = new CachedFileReader(reader)
const cached = new BatchedFileReader(reader)

await Promise.all(
['reject', 'resolve', 'reject', 'resolve'].map(async (directory) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FileReader } from './file-reader'

interface CachedFileReaderBatch {
interface FileReaderBatch {
completed: boolean
directories: Array<string>
callbacks: Array<{
Expand All @@ -13,8 +13,8 @@ interface CachedFileReaderBatch {
* CachedFileReader will deduplicate requests made to the same folder structure
* to scan for files.
*/
export class CachedFileReader implements FileReader {
private batch?: CachedFileReaderBatch
export class BatchedFileReader implements FileReader {
private batch?: FileReaderBatch

constructor(private readonly reader: FileReader) {}

Expand All @@ -30,13 +30,13 @@ export class CachedFileReader implements FileReader {
})
}

private getOrCreateBatch(): CachedFileReaderBatch {
private getOrCreateBatch(): FileReaderBatch {
// If there is an existing batch and it's not completed, then reuse it.
if (this.batch && !this.batch.completed) {
return this.batch
}

const batch: CachedFileReaderBatch = {
const batch: FileReaderBatch = {
completed: false,
directories: [],
callbacks: [],
Expand Down

0 comments on commit a35a740

Please sign in to comment.