Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse tmp dir for ipfs based projects #2551

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/common/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Expose CID on IPFS Reader (#2551)

## [5.1.1] - 2024-08-14
### Added
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/project/readers/ipfs-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class IPFSReader implements Reader {
private ipfs: IPFSHTTPClientLite;
private cache: Record<string, Promise<string>> = {};

constructor(private readonly cid: string, gateway?: string) {
constructor(readonly cid: string, gateway?: string) {
if (!CIDv0.test(cid) && !CIDv1.test(cid)) {
throw new Error('IPFS project path CID is not valid');
}
Expand Down
2 changes: 2 additions & 0 deletions packages/node-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Reuse the same temp dir when project is from IPFS (#2551)

## [14.1.3] - 2024-08-30
### Fixed
Expand Down
26 changes: 18 additions & 8 deletions packages/node-core/src/configure/configure.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import {handleCreateSubqueryProjectError, LocalReader, makeTempDir, ReaderFactory} from '@subql/common';
import fs from 'fs';
import os from 'os';
import path from 'path';
import {handleCreateSubqueryProjectError, IPFSReader, LocalReader, makeTempDir, ReaderFactory} from '@subql/common';
import {IEndpointConfig, Reader} from '@subql/types-core';
import {camelCase, isNil, omitBy} from 'lodash';
import {ISubqueryProject} from '../indexer';
Expand Down Expand Up @@ -64,13 +67,10 @@ export function yargsToIConfig(yargs: Args, nameMapping: Record<string, string>
value = [value];
}
if (Array.isArray(value)) {
value = value.reduce(
(acc, endpoint, index) => {
acc[endpoint] = endpointConfig[index] ?? {};
return acc;
},
{} as Record<string, IEndpointConfig>
);
value = value.reduce((acc, endpoint, index) => {
acc[endpoint] = endpointConfig[index] ?? {};
return acc;
}, {} as Record<string, IEndpointConfig>);
}
}
if (key === 'primary-network-endpoint') {
Expand All @@ -95,8 +95,18 @@ let rootDir: string;
async function getCachedRoot(reader: Reader, configRoot?: string): Promise<string> {
if (reader instanceof LocalReader) return reader.root;

// Case for in workers when the parent has decided the directory
if (configRoot) return configRoot;

// Allows reusing the same directory on restarts when project is run from ipfs, this can stop duplicating files in the tmp dir
if (reader instanceof IPFSReader) {
rootDir = path.resolve(os.tmpdir(), reader.cid);
if (!fs.existsSync(rootDir)) {
await fs.promises.mkdir(rootDir);
}
return rootDir;
}

if (!rootDir) {
rootDir = await makeTempDir();
}
Expand Down
Loading