Let's suppose that in a MYSQL database query, I need to pick up the last 1000 data that was posted, but within those results, the order must be growing (not descending, as would happen in ORDER BY ID DESC Limit 1000
).
The response of this data will be via JSON , using the json_encode
function of PHP , in a specific url, where who will capture and process this data is < strong> Javascript .
The question I have is the following: Considering examples 1, 2, and 3, and given that the data must be formatted in reverse order, which would be the most appropriate way, taking into account memory consumption and data processing speed?
1 - MYSQL
SELECT * FROM (
SELECT id, pessoa_id, chat
FROM chat
ORDER BY id DESC LIMIT 1000
) AS reverse_chat ORDER BY id ASC
2 - PHP
return Response::json(array_reverse($chat)); //lembrando que é $chat é um array com 1000 dados
3 - Javascript
$.ajax({
url: 'ajax_response',
dataType: 'json',
data: {pessoa_id: pessoa_id},
success: function(response){
// response também possui 1000 dados
var html = _.template(tpl_chat, {chat: response.reverse()});
}
})