Skip to content

Commit

Permalink
Merge pull request #887 from filecoin-project/@aminejv/viewer-improve…
Browse files Browse the repository at this point in the history
…ments

Improvement: update Viewer's getById method
  • Loading branch information
martinalong committed Aug 20, 2021
2 parents 2477bcb + e04c528 commit 862ccf8
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions node_common/managers/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,17 @@ export const getById = async ({ id }) => {

// user.library = await Data.getFilesByUserId({ id, sanitize: true });

const slates = await Data.getSlatesByUserId({
ownerId: id,
sanitize: true,
includeFiles: true,
});
const keys = await Data.getAPIKeysByUserId({ userId: id });
const subscriptions = await Data.getSubscriptionsByUserId({ ownerId: id });
const following = await Data.getFollowingByUserId({ ownerId: id });
const followers = await Data.getFollowersByUserId({ userId: id });
const [slates, keys, subscriptions, following, followers, { bucketRoot }] = (
await Promise.allSettled([
Data.getSlatesByUserId({ ownerId: id, sanitize: true, includeFiles: true }),
Data.getAPIKeysByUserId({ userId: id }),
Data.getSubscriptionsByUserId({ ownerId: id }),
Data.getFollowingByUserId({ ownerId: id }),
Data.getFollowersByUserId({ userId: id }),
Utilities.getBucketAPIFromUserToken({ user }),
])
).map((item) => item.value);

const libraryCids =
user?.library?.reduce((acc, file) => ({ ...acc, [file.cid]: file }), {}) || {};

Expand Down Expand Up @@ -201,10 +203,6 @@ export const getById = async ({ id }) => {

const tags = Utilities.getUserTags({ library: user.library, slates });

const { bucketRoot } = await Utilities.getBucketAPIFromUserToken({
user,
});

let viewer = {
id: user.id,
username: user.username,
Expand Down

0 comments on commit 862ccf8

Please sign in to comment.