Also store read progress in last_read table

This commit is contained in:
Kovid Goyal 2017-02-23 08:24:09 +05:30
parent 352a6d9238
commit 1beb7013f5
5 changed files with 10 additions and 10 deletions

View File

@ -135,7 +135,7 @@ CREATE TABLE last_read_positions ( id INTEGER PRIMARY KEY,
device TEXT NOT NULL,
cfi TEXT NOT NULL,
epoch REAL NOT NULL,
extra TEXT DEFAULT '',
pos_frac REAL NOT NULL DEFAULT 0,
UNIQUE(user, device, book, format)
);

View File

@ -2136,14 +2136,14 @@ class Cache(object):
def get_last_read_positions(self, book_id, fmt, user):
fmt = fmt.upper()
ans = []
for device, cfi, epoch in self.backend.execute(
'SELECT device,cfi,epoch FROM last_read_positions WHERE book=? AND format=? AND user=?',
for device, cfi, epoch, pos_frac in self.backend.execute(
'SELECT device,cfi,epoch,pos_frac FROM last_read_positions WHERE book=? AND format=? AND user=?',
(book_id, fmt, user)):
ans.append({'device':device, 'cfi': cfi, 'epoch':epoch})
ans.append({'device':device, 'cfi': cfi, 'epoch':epoch, 'pos_frac':pos_frac})
return ans
@write_api
def set_last_read_position(self, book_id, fmt, user='_', device='_', cfi=None, epoch=None):
def set_last_read_position(self, book_id, fmt, user='_', device='_', cfi=None, epoch=None, pos_frac=0):
fmt = fmt.upper()
device = device or '_'
user = user or '_'
@ -2153,8 +2153,8 @@ class Cache(object):
(book_id, fmt, user, device))
else:
self.backend.execute(
'INSERT OR REPLACE INTO last_read_positions(book,format,user,device,cfi,epoch) VALUES (?,?,?,?,?,?)',
(book_id, fmt, user, device, cfi, epoch or time()))
'INSERT OR REPLACE INTO last_read_positions(book,format,user,device,cfi,epoch,pos_frac) VALUES (?,?,?,?,?,?,?)',
(book_id, fmt, user, device, cfi, epoch or time(), pos_frac))
@read_api
def export_library(self, library_key, exporter, progress=None, abort=None):

View File

@ -652,7 +652,7 @@ CREATE TABLE last_read_positions ( id INTEGER PRIMARY KEY,
device TEXT NOT NULL,
cfi TEXT NOT NULL,
epoch REAL NOT NULL,
extra TEXT DEFAULT '',
pos_frac REAL NOT NULL DEFAULT 0,
UNIQUE(user, device, book, format)
);
DROP INDEX IF EXISTS lrp_idx;

Binary file not shown.

View File

@ -675,9 +675,9 @@ class ReadingTest(BaseTest):
self.assertFalse(cache.get_last_read_positions(1, 'x', 'u'))
self.assertRaises(Exception, cache.set_last_read_position, 12, 'x', cfi='c')
epoch = time()
cache.set_last_read_position(1, 'EPUB', 'user', 'device', 'cFi', epoch)
cache.set_last_read_position(1, 'EPUB', 'user', 'device', 'cFi', epoch, 0.3)
self.assertFalse(cache.get_last_read_positions(1, 'x', 'u'))
self.assertEqual(cache.get_last_read_positions(1, 'ePuB', 'user'), [{'epoch':epoch, 'device':'device', 'cfi':'cFi'}])
self.assertEqual(cache.get_last_read_positions(1, 'ePuB', 'user'), [{'epoch':epoch, 'device':'device', 'cfi':'cFi', 'pos_frac':0.3}])
cache.set_last_read_position(1, 'EPUB', 'user', 'device')
self.assertFalse(cache.get_last_read_positions(1, 'ePuB', 'user'))
# }}}