Skip to content

Commit

Permalink
Merge pull request #29 from CMU-17313Q/refactor-upload-file
Browse files Browse the repository at this point in the history
Refactoring code in src/user/uploads.js
  • Loading branch information
aattiyah authored Sep 23, 2024
2 parents 6d4b486 + 6e97243 commit 7fd8045
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/user/uploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ const _validatePath = async (relativePaths) => {
}
};

async function dissociateUploadsForPids(pids, idx, uploadNames) {
console.log('Ahmad');
return Promise.all(
pids.map(async pid => posts.uploads.dissociate(pid, uploadNames[idx]))
);
}

module.exports = function (User) {
User.associateUpload = async (uid, relativePath) => {
await _validatePath(relativePath);
Expand Down Expand Up @@ -70,9 +77,9 @@ module.exports = function (User) {

// Dissociate the upload from pids, if any
const pids = await db.getSortedSetsMembers(uploadNames.map(relativePath => `upload:${md5(relativePath)}:pids`));
await Promise.all(pids.map(async (pids, idx) => Promise.all(
pids.map(async pid => posts.uploads.dissociate(pid, uploadNames[idx]))
)));
await Promise.all(
pids.map((pids, idx) => dissociateUploadsForPids(pids, idx, uploadNames))
);
}, { batch: 50 });
};

Expand Down

0 comments on commit 7fd8045

Please sign in to comment.