I was finding on two sites that if feeds were set to update/replace on change of feed items that the feed enclosures were repeatedly being downloaded. Even though the item in the feed itself had not changed - the hash was different. This I finally worked out was caused by the simplepie object having elements in a different order:
array (
'type' => 'application/x-bittorrent;enclosed=video/ogg',
- 'url' => 'http://london.indymedia.org.uk/system/video/2010/01/27/4231/outofcontrol.mp4.ogg.torrent',
'isDefault' => 'true',
+ 'url' => 'http://london.indymedia.org.uk/system/video/2010/01/27/4231/outofcontrol.mp4.ogg.torrent',
),
),
A small patch that orders everything first, before hashing, solved this (on both sites).
(Note it will make different hashes from previous ones in the first instance, so everything gets repulled... after that it's stable).
| Comment | File | Size | Author |
|---|---|---|---|
| feeds.orderedhash.patch | 999 bytes | ekes |
Comments
Comment #1
ekes commentedComment #2
alex_b commentedWow. What odd behavior.
I have three concerns:
A We actually don't know whether we can convert $item to arrays. The architecture of Feeds allows you to pack anything you want into an item, this could be a SimpleXML object (I've built such a parser) or just an image.
B Such arrays could be potentially very large, recursively casting and sorting them could be expensive.
C If the item that you pass into hash() is an object, the recursion will have lasting effect on item and break the parser's getSourceElement() methods.
Two questions:
- Any idea why the order of elements in the feed items changes?
- What do you think about fixing the order of items in FeedsSimplePieParser?
Comment #3
ekes commentedI've looked at the code of the SimplePie parser, and it's looks like it should always come in at the same order - but it's 100s of repeated similar lines depending on different circumstances. However the feed items are identical. I've not found anything in searches about order in objects either.
Which brings to the the second question. It doesn't seem possible to order items in an object, and it is just taking the simplepie object wrapped. So I'm not sure how to do it in the parser without using an array instead, or making it a requirement of items to offer a id string - which as you mention because of the architecture isn't possible. (I did write the hash to try and only deal with arrays and objects passed, but it is almost certainly a big kick on performance).
Comment #4
kenorb commentedClosed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.