milesj / utility

[Deprecated] A CakePHP plugin for common utility classes.
MIT License
69 stars 24 forks source link

Updated the truncation to parse each feed #4

Closed TeckniX closed 11 years ago

TeckniX commented 11 years ago

Updated the read method to apply filter, sorting and truncation on each feed, instead of the overall feed results. If provided with 2+ feeds before, the results would truncate to the size of the first feed (10+ items always requested). The updated code, will truncate each feed to the size of $query['limit'], providing you with each feed filtered and sorted to the query limit count.

2 feed with a limit of 5, will return 10 feed entries (5 per feed).

resulting array is: array('feed-1-date'=>array(),       'feed-1-date'=>array(),       'feed-1-date'=>array(),       'feed-1-date'=>array(),       'feed-1-date'=>array(),       'feed-2-date'=>array(),       'feed-2-date'=>array(),       'feed-2-date'=>array(),       'feed-2-date'=>array(),       'feed-2-date'=>array()); Instead of: array('feed-1-date'=>array(),       'feed-1-date'=>array(),       'feed-1-date'=>array(),       'feed-1-date'=>array(),       'feed-1-date'=>array());

milesj commented 11 years ago

The order of the feeds is based on the timestamp: https://github.com/milesj/cake-utility/blob/master/Model/Datasource/FeedSource.php#L313

If the last 10 items in the feed are from a single source because of a newer timestamp, then those 10 should be returned during truncate. It shouldn't split it between multiple sources disregarding the date.

TeckniX commented 11 years ago

I see what you're saying - It's 2 different ways of looking at it, not sure if it's possible to support both. Basically you return the latest 10 items from an aggregation of feeds. I return the latest 10 items from each feed. I guess I could simply loop through the feeds and concatenate to an overall array.

Just odd that the FeedSource does it on its own, instead of the logic being in aggregation.

milesj commented 11 years ago

Well it's a datasource and needs to support the same options as if it was a regular database. But I could remove the limit of 20 restriction, and just have it return all if limit is null.

TeckniX commented 11 years ago

I think it's fine as-is then. I see the distinction. Thanks!