Skip to content

Commit

Permalink
move warp cache to memory
Browse files Browse the repository at this point in the history
  • Loading branch information
7i7o committed Aug 30, 2023
1 parent 0abbde0 commit 8e7bdca
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 52 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-keys-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@7i7o/pl-sync': patch
---

move warp cache to memory so it doesn't get synced with repo
5 changes: 1 addition & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { zipRepoJsZip } from './lib/zipHelper';
import { uploadRepo } from './lib/arweaveHelper';
import { getRepos, postRepoToWarp } from './lib/warpHelper';
import { getTags, getTitle, removeCacheFolder } from './lib/common';
import { getTags, getTitle } from './lib/common';

// Set up constants
const PATH = '.';
Expand All @@ -26,9 +26,6 @@ async function main() {

console.log(`[ PL Sync ] Starting sync for repo '${title}'`);

// delete warp cache folder
await removeCacheFolder();

// get existing repos for this wallet
const repos = await getRepos();

Expand Down
48 changes: 2 additions & 46 deletions src/lib/common.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import fs from 'fs';
import path from 'path';
import util from 'util';

// get info from secrets
import { config } from 'dotenv';
import { getAddress } from './arweaveHelper';
import { Tag } from 'arweave/node/lib/transaction';

// get info from secrets/env variables
import { config } from 'dotenv';
config();

export const getWallet = () => JSON.parse(process.env.WALLET as string);
Expand Down Expand Up @@ -35,43 +31,3 @@ export function getTags(createNewRepo: boolean) {

export const waitFor = (delay: number) =>
new Promise((res) => setTimeout(res, delay));

/* Function to remove warp cache folder before running */
export async function removeCacheFolder() {
const readdir = util.promisify(fs.readdir);
const rmdir = util.promisify(fs.rmdir);
const unlink = util.promisify(fs.unlink);
const stat = util.promisify(fs.stat);

async function removeFolderAndContents(folderPath: string) {
try {
const entries = await readdir(folderPath);

for (const entry of entries) {
const entryPath = path.join(folderPath, entry);
const entryStat = await stat(entryPath);

if (entryStat.isDirectory()) {
await removeFolderAndContents(entryPath);
} else {
await unlink(entryPath);
}
}

await rmdir(folderPath);
console.log(`Folder "${folderPath}" and its contents removed.`);
} catch (error) {
console.error('Error removing folder and contents:', error);
}
}

// Check if "cache" folder exists
const __dirname = '.';
const cacheFolderPath = path.join(__dirname, 'cache'); // Adjust the path if needed
fs.stat(cacheFolderPath, async (err, stats) => {
if (!err) {
// "cache" folder exists, remove it and its contents
await removeFolderAndContents(cacheFolderPath);
}
});
}
8 changes: 6 additions & 2 deletions src/lib/warpHelper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WarpFactory } from 'warp-contracts';
import { WarpFactory, defaultCacheOptions } from 'warp-contracts';
import { v4 as uuidv4 } from 'uuid';
import {
getDescription,
Expand All @@ -14,7 +14,11 @@ const contractTxId = getWarpContractTxId();
const title = getTitle();
const description = getDescription();

const getWarp = () => WarpFactory.forMainnet();
const getWarp = () =>
WarpFactory.forMainnet({
...defaultCacheOptions,
inMemory: true,
});
const contract = getWarp().contract(contractTxId).connect(jwk);

export async function getRepos() {
Expand Down

0 comments on commit 8e7bdca

Please sign in to comment.