B2G/gaia/apps/communications/dialer/js/call_log_db.js
/**
   * Ensures that the DB size is not bigger than _maxNumberOfGroups. If the DB
   * is fat enough, we delete the number of groups higher than
   * _maxNumberOfGroups (most likely 1) plus _numberOfGroupsToDelete to make
   * some extra space.
   */
Ensures that the DB size is not bigger than _maxNumberOfGroups. If the DB
is fat enough, we delete the number of groups higher than
_maxNumberOfGroups (most likely 1) plus _numberOfGroupsToDelete to make
some extra space.
Ensures that the DB size is not bigger than _maxNumberOfGroups . If the DB is fat enough we delete the number of groups higher than _maxNumberOfGroups ( most likely 1 ) plus _numberOfGroupsToDelete to make some extra space .
function _keepDbPrettyAndFit(callback) {
    var self = this;
    this._newTxn('readonly', this._dbGroupsStore, function(error, txn, store) {
      if (error) {
        return;
      }
      var req = store.count();
      req.onsuccess = function() {
        var groupsToDelete = req.result - self._maxNumberOfGroups;
        if (groupsToDelete > 0) {
          groupsToDelete += self._numberOfGroupsToDelete;
          var cursorReq = store.index('lastEntryDate').openCursor();
          cursorReq.onsuccess = function() {
            var cursor = cursorReq.result;
            if (!cursor || !groupsToDelete) {
              if (callback && callback instanceof Function) {
                callback();
              }
              return;
            }
            groupsToDelete--;
            self.deleteGroup(null, cursor.value.id);
            cursor.continue();
          };
        } else if (callback && callback instanceof Function) {
          callback();
        }
      };
    });
  }
function _keepDbPrettyAndFit ( callback ) { var self = this ; this . _newTxn ( 'readonly' , this . _dbGroupsStore , function ( error , txn , store ) { if ( error ) { return ; } var req = store . count ( ) ; req . onsuccess = function ( ) { var groupsToDelete = req . result - self . _maxNumberOfGroups ; if ( groupsToDelete > 0 ) { groupsToDelete += self . _numberOfGroupsToDelete ; var cursorReq = store . index ( 'lastEntryDate' ) . openCursor ( ) ; cursorReq . onsuccess = function ( ) { var cursor = cursorReq . result ; if ( ! cursor || ! groupsToDelete ) { if ( callback && callback instanceof Function ) { callback ( ) ; } return ; } groupsToDelete -- ; self . deleteGroup ( null , cursor . value . id ) ; cursor . continue ( ) ; } ; } else if ( callback && callback instanceof Function ) { callback ( ) ; } } ; } ) ; }
Ensures that the DB size is not bigger than _maxNumberOfGroups.
Ensures that the DB size is not bigger than _maxNumberOfGroups .