Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix: use process concurrently helper

mertmit546eea9b68b4
diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts
index 7752b19161..827babf3d7 100644
--- a/packages/nocodb/src/db/BaseModelSqlv2.ts
+++ b/packages/nocodb/src/db/BaseModelSqlv2.ts
@@ -124,6 +124,7 @@ import {
generateAuditV1Payload,
nocoExecute,
populateUpdatePayloadDiff,
+ processConcurrently,
remapWithAlias,
removeBlankPropsAndMask,
} from '~/utils';
@@ -5677,27 +5678,24 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
}
}
- const batchSize = 15;
-
- // Process attachments in batches
- for (let i = 0; i < allAttachments.length; i += batchSize) {
- const batch = allAttachments.slice(i, i + batchSize);
- const batchPromises = batch.map(
- (attachment) =>
- PresignedUrl.signAttachment({
- attachment,
- filename: attachment.title,
- }).catch(() => {}), // Ignore individual failures
- );
- await Promise.all(batchPromises);
- }
+ await processConcurrently(
+ allAttachments,
+ async (item) => {
+ try {
+ await PresignedUrl.signAttachment({
+ attachment: item,
+ filename: item.title,
+ });
+ } catch (e) {}
+ },
+ 15,
+ );
- // Process thumbnails in batches
- for (let i = 0; i < allThumbnails.length; i += batchSize) {
- const batch = allThumbnails.slice(i, i + batchSize);
- const batchPromises = batch.map(
- ({ attachment, thumbnailKey, thumbnailPath }) =>
- PresignedUrl.signAttachment({
+ await processConcurrently(
+ allThumbnails,
+ async ({ attachment, thumbnailKey, thumbnailPath }) => {
+ try {
+ await PresignedUrl.signAttachment({
attachment: {
...attachment,
...(attachment.path
@@ -5707,10 +5705,11 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
filename: attachment.title,
mimetype: 'image/jpeg',
nestedKeys: ['thumbnails', thumbnailKey],
- }).catch(() => {}), // Ignore individual failures
- );
- await Promise.all(batchPromises);
- }
+ });
+ } catch (e) {}
+ },
+ 15,
+ );
} catch (error) {
// Log error but don't throw to avoid breaking the entire response
console.warn('Error in _convertAttachmentType:', error.message);
diff --git a/packages/nocodb/src/models/PresignedUrl.ts b/packages/nocodb/src/models/PresignedUrl.ts
index 67e1d0299b..33639dedd4 100644
--- a/packages/nocodb/src/models/PresignedUrl.ts
+++ b/packages/nocodb/src/models/PresignedUrl.ts
@@ -10,6 +10,7 @@ import NocoCache from '~/cache/NocoCache';
import { CacheGetType, CacheScope } from '~/utils/globals';
import { getPathFromUrl, isPreviewAllowed } from '~/helpers/attachmentHelpers';
import { parseMetaProp } from '~/utils/modelUtils';
+import { processConcurrently } from '~/utils/dataUtils';
function roundExpiry(date) {
const msInTenMinutes = 10 * 60 * 1000;
@@ -318,14 +319,15 @@ export default class PresignedUrl {
}
}
- const batchSize = 15;
- for (let i = 0; i < allItems.length; i += batchSize) {
- const batch = allItems.slice(i, i + batchSize);
- const batchPromises = batch.map(
- (item) => PresignedUrl.signAttachment(item).catch(() => {}), // Ignore individual failures
- );
- await Promise.all(batchPromises);
- }
+ await processConcurrently(
+ allItems,
+ async (item) => {
+ try {
+ await PresignedUrl.signAttachment(item);
+ } catch (e) {}
+ },
+ 15,
+ );
} catch (e) {
logger.error('Error signing meta icon image', e);
}