Skip to content

Commit e378cf7

Browse files
committed
Update cloudinary rotation to purely random to avoid throttling
1 parent a9c5528 commit e378cf7

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Treasure_Hunt_Backend/src/utils/cloudinaryUploader.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@ const initConfigs = () => {
4141
console.log(`☁️ Loaded ${configs.length} Cloudinary account(s)`);
4242
};
4343

44-
// Get next config (round-robin)
45-
const getNextConfig = () => {
44+
// Get a random config to ensure load balancing across accounts
45+
const getRandomConfig = () => {
4646
initConfigs();
4747
if (configs.length === 0) throw new Error('No Cloudinary configs available');
48-
const config = configs[currentIndex % configs.length];
49-
currentIndex++;
50-
return config;
48+
const randomIndex = Math.floor(Math.random() * configs.length);
49+
return configs[randomIndex];
5150
};
5251

5352
/**
@@ -57,7 +56,7 @@ const getNextConfig = () => {
5756
* @returns {Promise<string>} - The secure URL of the uploaded image
5857
*/
5958
export const uploadToCloudinary = async (fileBuffer, folder = 'treasure_hunt') => {
60-
const config = getNextConfig();
59+
const config = getRandomConfig();
6160

6261
cloudinary.config({
6362
cloud_name: config.cloud_name,

0 commit comments

Comments
 (0)