From 549b6d3e09d8f745a3ed090ff365948d1d943693 Mon Sep 17 00:00:00 2001 From: David Snopek Date: Wed, 31 Jul 2013 20:17:26 +0100 Subject: [PATCH] Added a way to get recently updated notes. --- AnkiServer/apps/rest_app.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/AnkiServer/apps/rest_app.py b/AnkiServer/apps/rest_app.py index 5bb0ecf..84c05f6 100644 --- a/AnkiServer/apps/rest_app.py +++ b/AnkiServer/apps/rest_app.py @@ -303,11 +303,29 @@ class CollectionHandler(RestHandlerBase): ids = col.findNotes(query) if req.data.get('preload', False): - nodes = [NoteHandler._serialize(col.getNote(id)) for id in ids] + notes = [NoteHandler._serialize(col.getNote(id)) for id in ids] else: - nodes = [{'id': id} for id in ids] + notes = [{'id': id} for id in ids] - return nodes + return notes + + def latest_notes(self, col, req): + # TODO: use SQLAlchemy objects to do this + sql = "SELECT n.id FROM notes AS n"; + args = [] + if req.data.has_key('updated_since'): + sql += ' WHERE n.mod > ?' + args.append(req.data['updated_since']) + sql += ' ORDER BY n.mod DESC' + sql += ' LIMIT ' + str(req.data.get('limit', 10)) + ids = col.db.list(sql, *args) + + if req.data.get('preload', False): + notes = [NoteHandler._serialize(col.getNote(id)) for id in ids] + else: + notes = [{'id': id} for id in ids] + + return notes @noReturnValue def add_note(self, col, req):