File tree Expand file tree Collapse file tree 1 file changed +5
-6
lines changed
Treasure_Hunt_Backend/src/utils Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Original file line number Diff line number Diff 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 */
5958export 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 ,
You can’t perform that action at this time.
0 commit comments