sort ref_list so newly added is first.

This commit is contained in:
Jason Schwarzenberger 2020-11-24 17:28:24 +13:00
parent 2439c113b3
commit 5c96092a57

View File

@ -147,16 +147,19 @@ def static_story(sid):
http_server = WSGIServer(('', settings.API_PORT or 33842), flask_app) http_server = WSGIServer(('', settings.API_PORT or 33842), flask_app)
def _add_new_refs(): def _add_new_refs():
added = []
for ref, source, urlref in feed.get_list(): for ref, source, urlref in feed.get_list():
if database.get_story_by_ref(ref): if database.get_story_by_ref(ref):
continue continue
try: try:
nid = new_id() nid = new_id()
database.put_ref(ref, nid, source, urlref) database.put_ref(ref, nid, source, urlref)
added.append(ref)
logging.info('Added ref ' + ref) logging.info('Added ref ' + ref)
except database.IntegrityError: except database.IntegrityError:
logging.info('Unable to add ref ' + ref) logging.info('Unable to add ref ' + ref)
continue continue
return added
def _update_current_story(item): def _update_current_story(item):
try: try:
@ -183,8 +186,9 @@ def feed_thread():
while True: while True:
# onboard new stories # onboard new stories
if not len(ref_list): if not len(ref_list):
_add_new_refs() added = _add_new_refs()
ref_list = database.get_reflist() ref_list = database.get_reflist()
ref_list.sort(key=lambda i: i['ref'] in added, reverse=True)
# update current stories # update current stories
if len(ref_list): if len(ref_list):