- for source, source_config in update_config.iteritems():
- source_config2 = source_config.copy()
- hook_name = 'frontpage_updates_' + source_config2.pop('__type__')
- source_config2.update(global_config)
-
- # Hooks should return a list of FrontPageUpdate objects, making this
- # return value a list of lists
- updates_lol = run_hooks(hook_name, **source_config2)
- updates += sum(updates_lol, [])
-
- # Sort everything by descending time, then crop to the right number of
- # items
- updates.sort(key=lambda obj: obj.time)
- updates.reverse()
- c.updates = updates[:global_config['limit']]
+ global_limit = config['spline-frontpage.limit']
+ global_max_age = max_age_to_datetime(
+ config['spline-frontpage.max_age'])
+
+ c.sources = config['spline-frontpage.sources']
+ for source in c.sources:
+ new_updates = source.poll(global_limit, global_max_age)
+ updates.extend(new_updates)
+
+ # Little optimization: once there are global_limit items, anything
+ # older than the oldest cannot possibly make it onto the list. So,
+ # bump global_max_age to that oldest time if this is ever the case.
+ updates.sort(key=lambda obj: obj.time, reverse=True)
+ del updates[global_limit:]
+
+ if updates and len(updates) == global_limit:
+ global_max_age = updates[-1].time
+
+ # Done! Feed to template
+ c.updates = updates