Skip to content

Commit

Permalink
fix: when file is not cached read it from file (#82)
Browse files Browse the repository at this point in the history
liveDirectory cache at most 250 files each big at most 1MB
  • Loading branch information
matteo-cristino authored Mar 7, 2024
1 parent d933b51 commit 421bace
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/directory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import LiveDirectory from 'live-directory';
import fs from 'fs';
import { config } from './cli.js';
import { Endpoints } from './types.js';
import { validateJSONSchema, newMetadata } from './utils.js';
Expand All @@ -23,7 +24,10 @@ export class Directory {
}

private getContent(name: string) {
return this.liveDirectory.get(name)?.content.toString('utf-8');
const lf = this.liveDirectory.get(name);
if (lf == null) return lf;
if (lf.cached) return lf.content.toString('utf-8');
else return fs.readFileSync(lf.path).toString('utf-8');
}

public static getInstance(): Directory {
Expand All @@ -44,7 +48,7 @@ export class Directory {
if (ext === 'zen') {
result.push({
path: path,
contract: formatContract(Buffer.from(c.content).toString('utf-8')),
contract: formatContract(this.getContent(f)),
keys: this.getJSON(path, 'keys'),
conf: this.getContent(path + '.conf') || '',
schema: this.getJSONSchema(path),
Expand Down

0 comments on commit 421bace

Please sign in to comment.