Skip to content

Commit

Permalink
fix: fix opt-in pagination and attempt to speed up email list endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Aug 21, 2024
1 parent 4aab992 commit 12c253b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
4 changes: 3 additions & 1 deletion app/controllers/web/my-account/list-domains.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ async function listDomains(ctx, next) {
// (unless user opts in beforehand using ?pagination=true)
//
const hasPagination = dayjs().isBefore('11/1/2024', 'M/D/YYYY')
? boolean(ctx.query.pagination)
? boolean(ctx.query.pagination) ||
!_.isUndefined(ctx.query.limit) ||
!_.isUndefined(ctx.query.page)
: true;

//
Expand Down
15 changes: 2 additions & 13 deletions app/controllers/web/my-account/list-emails.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ const { Domains, Emails, Aliases } = require('#models');
// eslint-disable-next-line complexity
async function listEmails(ctx, next) {
// user must be domain admin or alias owner of the email
const [domains, aliases, goodDomains, count] = await Promise.all([
const [domains, aliases, count] = await Promise.all([
Domains.distinct('_id', {
has_smtp: true,
is_smtp_suspended: false,
members: {
$elemMatch: {
user: ctx.state.user._id,
Expand All @@ -30,10 +28,6 @@ async function listEmails(ctx, next) {
Aliases.distinct('_id', {
user: ctx.state.user._id
}),
Domains.distinct('_id', {
has_smtp: true,
is_smtp_suspended: false
}),
ctx.client.zcard(`${config.smtpLimitNamespace}:${ctx.state.user.id}`)
]);

Expand All @@ -46,8 +40,7 @@ async function listEmails(ctx, next) {
let query = {
$or: [
{
alias: { $in: aliases },
domain: { $in: goodDomains }
alias: { $in: aliases }
},
{
domain: { $in: domains }
Expand Down Expand Up @@ -78,10 +71,6 @@ async function listEmails(ctx, next) {
)
);

// domain cannot be in suspended domains list
if (_.isDate(domain.smtp_suspended_sent_at))
throw Boom.badRequest(ctx.translateError('DOMAIN_SUSPENDED'));

// if domain has not yet been setup yet then alert user
if (
!ctx.api &&
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/web/my-account/retrieve-aliases.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ async function retrieveAliases(ctx, next) {
// (unless user opts in beforehand using ?pagination=true)
//
const hasPagination = dayjs().isBefore('11/1/2024', 'M/D/YYYY')
? boolean(ctx.query.pagination)
? boolean(ctx.query.pagination) ||
!_.isUndefined(ctx.query.limit) ||
!_.isUndefined(ctx.query.page)
: true;

//
Expand Down
9 changes: 7 additions & 2 deletions routes/api/v1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

const Router = require('@koa/router');
const _ = require('lodash');
const bodyParser = require('koa-bodyparser');
const dayjs = require('dayjs-with-plugins');
const multer = require('@koa/multer');
Expand Down Expand Up @@ -175,7 +176,9 @@ router
// (unless user opts in beforehand using ?pagination=true)
//
const hasPagination = dayjs().isBefore('11/1/2024', 'M/D/YYYY')
? boolean(ctx.query.pagination)
? boolean(ctx.query.pagination) ||
!_.isUndefined(ctx.query.limit) ||
!_.isUndefined(ctx.query.page)
: true;
if (!hasPagination) return next();
if (typeof ctx.query.limit === 'undefined') ctx.query.limit = 1000;
Expand Down Expand Up @@ -286,7 +289,9 @@ router
// (unless user opts in beforehand using ?pagination=true)
//
const hasPagination = dayjs().isBefore('11/1/2024', 'M/D/YYYY')
? boolean(ctx.query.pagination)
? boolean(ctx.query.pagination) ||
!_.isUndefined(ctx.query.limit) ||
!_.isUndefined(ctx.query.page)
: true;
if (!hasPagination) return next();
if (typeof ctx.query.limit === 'undefined') ctx.query.limit = 1000;
Expand Down

0 comments on commit 12c253b

Please sign in to comment.