@ -609,27 +609,129 @@ Storage.prototype.storeActiveAddresses = function(walletId, addresses, cb) {
} , cb ) ;
} ;
// -------- --------------------------- Total
// > Time >
// ^to <= ^from
// ^start => ^end
Storage . prototype . storeTxHistoryCache = function ( walletId , firstPosition , items , cb ) {
Storage . prototype . get TxHistoryCache = function ( walletId , from , to , cb ) {
var self = this ;
self . db . collection ( collections . CACHE ) . findOne ( {
walletId : record . walletId ,
type : 'historyCache'
walletId : walletId ,
type : 'historyCacheStatus' ,
key : null
} , function ( err , result ) {
if ( err ) return cb ( err ) ;
if ( ! result ) return cb ( ) ;
// Reverse indexes
var start = result . totalItems - from ;
var end = start + to - from ;
console . log ( '[storage.js.632] from,to:' , from , to ) ; //TODO
console . log ( '[storage.js.632] start,end:' , start , end ) ; //TODO
// Cache is OK.
self . db . collection ( collections . CACHE ) . findOne ( {
walletId : walletId ,
type : 'historyCache' ,
key : null
} , function ( err , result ) {
console . log ( '[storage.js.641:result:]' , result ) ; //TODO
if ( err ) return cb ( err ) ;
if ( ! _ . any ( result . history , function ( i ) {
return ! ! i ;
} ) ) return cb ( ) ; // some items are not yet defined.
var ret = result . history . slice ( start , end ) ;
return cb ( null , ret ) ;
} ) ;
} )
} ;
Storage . prototype . softResetTxHistoryCache = function ( walletId , cb ) {
this . db . collection ( collections . CACHE ) . remove ( {
walletId : walletId ,
type : 'historyCacheStatus' ,
key : null
} , {
w : 1
} , cb ) ;
} ;
Storage . prototype . clearTxHistoryCache = function ( walletId , cb ) {
var self = this ;
self . db . collection ( collections . CACHE ) . remove ( {
walletId : walletId ,
type : 'historyCache' ,
key : null
} , {
w : 1
} , function ( err ) {
self . db . collection ( collections . CACHE ) . remove ( {
walletId : walletId ,
type : 'historyCacheStatus' ,
key : null
} , {
w : 1
} , cb ) ;
} ) ;
} ;
Storage . prototype . storeTxHistoryCache = function ( walletId , totalItems , firstPosition , itemsLastFirst , cb ) {
$ . shouldBeNumber ( firstPosition ) ;
$ . checkArgument ( firstPosition >= 0 ) ;
$ . shouldBeNumber ( totalItems ) ;
$ . checkArgument ( totalItems >= 0 ) ;
var self = this ;
self . db . collection ( collections . CACHE ) . findOne ( {
walletId : walletId ,
type : 'historyCache' ,
key : null
} , function ( err , result ) {
if ( err ) return cb ( err ) ;
result = result || [ ] ;
result
self . db . collection ( collections . CACHE ) . update ( {
walletId : record . walletId ,
type : record . type ,
key : record . key ,
} , record , {
//create a sparce array, from the reversed input
_ . each ( itemsLastFirst . reverse ( ) , function ( i ) {
result [ firstPosition ++ ] = i ;
} ) ;
var cacheIsReady = ! ! result [ 0 ] ;
var now = Date . now ( ) ;
self . db . collection ( collections . CACHE ) . update ( {
walletId : walletId ,
type : 'historyCacheStatus' ,
key : null
} , {
totalItems : totalItems ,
updatedOn : now ,
} , {
w : 1 ,
upsert : true ,
} , next ) ;
} , cb ) ;
} , function ( err ) {
if ( err ) return cb ( err ) ;
self . db . collection ( collections . CACHE ) . update ( {
walletId : walletId ,
type : 'historyCache' ,
key : null
} , {
history : result
} , {
w : 1 ,
upsert : true ,
} , cb ) ;
} ) ;
} ) ;
} ;