Skip to content

Commit

Permalink
better entre exist check
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Feb 21, 2024
1 parent 0d7bd4a commit 1fc1298
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lib/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ class Account {
let retries = 0;
while (retries++ < 20) {
id = nanoid();
let alreadyExists = await this.redis.exists(`${REDIS_PREFIX}iad:${id}`);
let alreadyExists = await this.redis.hexists(`${REDIS_PREFIX}iad:${id}`, 'account');
if (alreadyExists) {
id = false;
} else {
Expand Down Expand Up @@ -1206,11 +1206,13 @@ class Account {
options,
timeout: this.timeout
});

if (!messageData) {
let message = 'Requested message was not found';
let error = Boom.boomify(new Error(message), { statusCode: 404 });
throw error;
}

return messageData;
}

Expand Down
1 change: 1 addition & 0 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2878,6 +2878,7 @@ class Connection {
let content = await this.getAttachmentContent(attachment.reference, {
chunkSize: Math.max(DOWNLOAD_CHUNK_SIZE, 2 * 1024 * 1024)
});

if (!content) {
let error = new Error('Referenced attachment was not found');
error.code = 'ReferenceNotFound';
Expand Down
2 changes: 1 addition & 1 deletion lib/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Gateway {
let retries = 0;
while (retries++ < 20) {
id = nanoid();
let alreadyExists = await this.redis.exists(`${REDIS_PREFIX}iad:${id}`);
let alreadyExists = await this.redis.hexists(`${REDIS_PREFIX}gateway:${id}`, 'gateway');
if (alreadyExists) {
id = false;
} else {
Expand Down
6 changes: 3 additions & 3 deletions workers/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ const documentsWorker = new Worker(

// returns indexing response for the parent job
case MESSAGE_NEW_NOTIFY: {
let accountExists = await redis.exists(`${REDIS_PREFIX}iad:${job.data.account}`);
let accountExists = await redis.hexists(`${REDIS_PREFIX}iad:${job.data.account}`, 'account');
if (!accountExists) {
// deleted account?
return false;
Expand Down Expand Up @@ -698,7 +698,7 @@ const documentsWorker = new Worker(
let messageData = job.data.data;
let messageId = messageData.id;

let accountExists = await redis.exists(`${REDIS_PREFIX}iad:${job.data.account}`);
let accountExists = await redis.hexists(`${REDIS_PREFIX}iad:${job.data.account}`, 'account');
if (!accountExists) {
// deleted account?
return;
Expand Down Expand Up @@ -805,7 +805,7 @@ ${Object.keys(params)
return;
}

let accountExists = await redis.exists(`${REDIS_PREFIX}iad:${job.data.account}`);
let accountExists = await redis.hexists(`${REDIS_PREFIX}iad:${job.data.account}`, 'account');
if (!accountExists) {
// deleted account?
return;
Expand Down
2 changes: 1 addition & 1 deletion workers/webhooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const notifyWorker = new Worker(
let accountKey = getAccountKey(job.data.account);

// validate if we should even process this webhook
let accountExists = await redis.exists(accountKey);
let accountExists = await redis.hexists(accountKey, 'account');
if (!accountExists && job.name !== ACCOUNT_DELETED_NOTIFY) {
logger.debug({
msg: 'Account is not enabled',
Expand Down

0 comments on commit 1fc1298

Please sign in to comment.