Skip to content

Mysql crash after foreach create #279

@nezzard

Description

@nezzard

Hi, i try to create posts inside foreach, but i think something wrong, bcs my mysql crash after that, can you tell me, how i can fix this?
Maybe something like delay?

result.forEach(function(item){
	wp.song().search( item['artist']+' - '+item['song'] ).then(function( posts ) {
		if(!posts[0]){

			var myRequests = [];
			myRequests.push(rp({uri: "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist="+encodeURIComponent(item['artist'])+"&api_key=[key]&format=json", json: true}));
			myRequests.push(rp({uri: "https://www.googleapis.com/youtube/v3/search?part=snippet&order=viewCount&q="+encodeURIComponent(item['artist']+'+'+item['song'])+"&type=video&key=[key]", json: true}));
			Promise.all(myRequests)
			  .then((arrayOfHtml) => {
			  	console.log(arrayOfHtml[0]['artist']['image'][2]['#text']);
			    console.log(arrayOfHtml[1]['items'][0]['id'].videoId);


					wp.posts().create({
					    title: item['artist']+' - '+item['song'],
					    content: 'Your post content',
					    status: 'publish'
					}).then(function( response ) {
					    console.log( response.id );
					})

			    
			  })
			  .catch(/* handle error */);


		}
	});
})

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions