From 5c96092a57a53eac1716d90606d552d4a0c48d72 Mon Sep 17 00:00:00 2001 From: Jason Schwarzenberger Date: Tue, 24 Nov 2020 17:28:24 +1300 Subject: [PATCH] sort ref_list so newly added is first. --- apiserver/server.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apiserver/server.py b/apiserver/server.py index b831746..f96203f 100644 --- a/apiserver/server.py +++ b/apiserver/server.py @@ -147,16 +147,19 @@ def static_story(sid): http_server = WSGIServer(('', settings.API_PORT or 33842), flask_app) def _add_new_refs(): + added = [] for ref, source, urlref in feed.get_list(): if database.get_story_by_ref(ref): continue try: nid = new_id() database.put_ref(ref, nid, source, urlref) + added.append(ref) logging.info('Added ref ' + ref) except database.IntegrityError: logging.info('Unable to add ref ' + ref) continue + return added def _update_current_story(item): try: @@ -183,8 +186,9 @@ def feed_thread(): while True: # onboard new stories if not len(ref_list): - _add_new_refs() + added = _add_new_refs() ref_list = database.get_reflist() + ref_list.sort(key=lambda i: i['ref'] in added, reverse=True) # update current stories if len(ref_list):