newdb: Fix book_id->row mapping broken when asearch is in effect

This commit is contained in:
Kovid Goyal 2013-07-30 14:33:20 +05:30
parent 11ab767266
commit 60cf6c4c5d
2 changed files with 12 additions and 1 deletions

View File

@ -192,6 +192,7 @@ class LegacyTest(BaseTest):
'has_id':[(1,), (2,), (3,), (9999,)],
'id':[(1,), (2,), (0,),],
'index':[(1,), (2,), (3,), ],
'row':[(1,), (2,), (3,), ],
'is_empty':[()],
'count':[()],
'all_author_names':[()],
@ -254,6 +255,12 @@ class LegacyTest(BaseTest):
o = {type('')(k) if isinstance(k, bytes) else k:set(v) if isinstance(v, list) else v for k, v in o.iteritems()}
n = {k:set(v) if isinstance(v, list) else v for k, v in n.iteritems()}
self.assertEqual(o, n)
ndb.search('title:Unknown')
db.search('title:Unknown')
self.assertEqual(db.row(3), ndb.row(3))
self.assertRaises(ValueError, ndb.row, 2)
self.assertRaises(ValueError, db.row, 2)
db.close()
# }}}

View File

@ -178,9 +178,13 @@ class View(object):
return self._map_filtered[idx]
def id_to_index(self, book_id):
return self._map.index(book_id)
return self._map_filtered.index(book_id)
row = index_to_id
def index(self, book_id, cache=False):
x = self._map if cache else self._map_filtered
return x.index(book_id)
def _get(self, field, idx, index_is_id=True, default_value=None, fmt=lambda x:x):
id_ = idx if index_is_id else self.index_to_id(idx)
if index_is_id and not self.cache.has_id(id_):