Welcome Guest, Not a member yet? Register   Sign In
Process Twitter search results recursively
#1

[eluser]dazzer[/eluser]
I have a cron job that calls my controller ( that works only for cli requests ) every 30 minutes. The cron calls a method ( startSearch ) that calls another method from the same controller - "doSearch()".

Inside the "doSearch" method I use cURL to make a request to the twitter rest api ( deprecated version now ).
Everything is working as expected, and if there are more than 100 ( the results/page number I use when making the request ) results I will have a "nextPage" field inside the returned result.

If "nextPage" exsists, I call "$this->doSearch()" again with different parameters. The whole process works just fine, but I don't feel using recursion inside a controller like this is the right way to do this task.

So my actual question, is the recursion inside a controller a good practice ? Should I do it inside a library or something else ?

There is no use for code here because everything is working, I just have a bad feeling about the recursion.

Thank you.

#2

[eluser]vitoco[/eluser]
I think that recursion in this case isn't necessary if you can get the total count of items, if you can get it, just put the "doSearch" call inside a for loop that increment the index +100 on every cicle, or inside a while that do the same . Also recursion it's expensive in resources...it stores the whole previous call ( all of them ) on memory until the current (last one) call return something....so if you have 1000 result you will have 9 "doSearch" calls in memory before the last one gets executed.

Saludso
#3

[eluser]dazzer[/eluser]
I don't know how many results there at any time. I just use data cursoring ( described in the twitter docs ) and go down until I find the last processed item ( stored in db ). So there is no incrementing or anything. I just check if there is a next page.

Still, your idea will work. I will do everything inside a while loop, without making a call to the same method.

Thank you !




Theme © iAndrew 2016 - Forum software by © MyBB