Skip to content

Commit

Permalink
chore: added log to get usage with redis and fallback to usage withou…
Browse files Browse the repository at this point in the history
…t cache for testing
  • Loading branch information
apsantiso committed Jun 18, 2024
1 parent af72fd9 commit 90d58da
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/app/routes/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ class BridgeController {
}

async getUsage(req: Request, res: Response) {
const usage = await this.service.User.getUsage((req as AuthorizedRequest).user);
let usage;
try{
usage = await this.service.User.getUsage((req as AuthorizedRequest).user);
}catch(err){
console.error(err);

Check warning on line 20 in src/app/routes/bridge.ts

View workflow job for this annotation

GitHub Actions / run-tests (16.x)

Unexpected console statement

Check warning on line 20 in src/app/routes/bridge.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected console statement
}

if(!usage){
console.log('Getting usage without using redis')

Check warning on line 24 in src/app/routes/bridge.ts

View workflow job for this annotation

GitHub Actions / run-tests (16.x)

Unexpected console statement

Check failure on line 24 in src/app/routes/bridge.ts

View workflow job for this annotation

GitHub Actions / run-tests (16.x)

Missing semicolon

Check warning on line 24 in src/app/routes/bridge.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected console statement

Check failure on line 24 in src/app/routes/bridge.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing semicolon
usage = await this.service.User.getUsageWithoutCache((req as AuthorizedRequest).user)

Check failure on line 25 in src/app/routes/bridge.ts

View workflow job for this annotation

GitHub Actions / run-tests (16.x)

Missing semicolon

Check failure on line 25 in src/app/routes/bridge.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing semicolon
}

res.status(200).send(usage);
}
Expand Down
28 changes: 28 additions & 0 deletions src/app/services/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,33 @@ module.exports = (Model, App) => {
};
};

const getUsageWithoutCache = async user => {
const targetUser = await Model.users.findOne({ where: { username: user.bridgeUser } });

const usage = await Model.file.findAll({
where: { user_id: targetUser.id, status: { [Op.ne]: 'DELETED' } },
attributes: [[fn('sum', col('size')), 'total']],
raw: true,
});

driveUsage = parseInt(usage[0].total);

Check failure on line 556 in src/app/services/user.js

View workflow job for this annotation

GitHub Actions / run-tests (16.x)

'driveUsage' is not defined

Check failure on line 556 in src/app/services/user.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'driveUsage' is not defined

const backupsQuery = await Model.backup.findAll({
where: { userId: targetUser.id },
attributes: [[fn('sum', col('size')), 'total']],
raw: true,
});

const backupsUsage = parseInt(backupsQuery[0].total ? backupsQuery[0].total : 0);

return {
total: driveUsage + backupsUsage,

Check failure on line 567 in src/app/services/user.js

View workflow job for this annotation

GitHub Actions / run-tests (16.x)

'driveUsage' is not defined

Check failure on line 567 in src/app/services/user.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'driveUsage' is not defined
_id: user.email,
drive: driveUsage || 0,

Check failure on line 569 in src/app/services/user.js

View workflow job for this annotation

GitHub Actions / run-tests (16.x)

'driveUsage' is not defined

Check failure on line 569 in src/app/services/user.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'driveUsage' is not defined
backups: backupsUsage,
};
};

const UpdateUserStorage = async (email, maxSpaceBytes) => {
const { GATEWAY_USER, GATEWAY_PASS } = process.env;

Expand Down Expand Up @@ -821,6 +848,7 @@ module.exports = (Model, App) => {
recoverPassword,
invite,
deactivate,
getUsageWithoutCache,
confirmDeactivate,
findWorkspaceMembers,
UserAlreadyRegisteredError,
Expand Down

0 comments on commit 90d58da

Please sign in to comment.