cordovaSQLite retrieving data slowly using ionic framework

I am making an application using the ionic framework and I am using sqlite to store a list of about 150 rows. Each row has two attributes, ID and Name.

Now I am retrieving this data using a database factory which runs a query.

It works, however when I test it on an my Galaxy Tab 3 the list takes about 5-10 seconds to load and once it it loaded the list it super laggy scrolling through the list items.

Here's my controller

.controller('ActionSearchCtrl', function($scope, ActionSearchDataService, DBA, $cordovaSQLite){

    var tablet = true;
    var query = "select action FROM actions;";


    $scope.items = []; 

    $scope.runSQL = function(){
        DBA.query(query).then(function(result){
            $scope.items = DBA.getAll(result);
        });
    }; 

    if(tablet){$scope.runSQL()};

Here's my Database Factory

.factory('DBA', function($cordovaSQLite, $q, $ionicPlatform) {
  var self = this;

  // Handle query's and potential errors
 self.query = function (query, parameters) {
    parameters = parameters || [];
    var q = $q.defer();

    $ionicPlatform.ready(function () {
      $cordovaSQLite.execute(herbsDatabase, query, parameters)
      .then(function (result) {
        q.resolve(result);
      }, function (error) {
        console.warn('I found an error');
        console.warn(error);
        alert(error.message);
        q.reject(error);
      });
    });
    return q.promise;
  }

  // Proces a result set
  self.getAll = function(result) {
    var output = [];
    for (var i = 0; i < result.rows.length; i++) {
      output.push(result.rows.item(i));
    }
    return output;
  }


  // Proces a single result
  self.getById = function(result) {
    var output = null;
    output = angular.copy(result.rows.item(0));
    return output;
  }
  return self;
})

So the query returns about 150 entries which I need all on one page (I've looked into infinite scrolling and pagination but my client wants all the items on one page so this is not an option. From what I've read, 150 entries shouldn't be too slow in terms of watchers as I am using ng-repeat for the list items to display. If anyone has a way I can display this many items using the cordovaSQLite plugin to make the list function quicker let me know! at the moment the list is pretty much unusable, I've tried it on other devices too and it has the same result.

I've also tried creating about 200 dummy objects in the controller (without making a call to the db to get data) and the performance is fine. That's why I am thinking it's an SQLite performance issue. This is my first post on here so apologies if I am not clear enough.

Your problem may comes from several points.

Are you running on Android?

First, if you are running on android, be aware that list management and SCROLLING is pretty lame at present on ionic. On my case, only Native scroll was providing good results with keeping ng-repeat.

app.config(function($ionicConfigProvider) {
    if(ionic.Platform.isAndroid())
       $ionicConfigProvider.scrolling.jsScrolling(false);
});

Fasting up SQLite

I have clearly improved my performance of SQLite by defining correct index with this command :

'CREATE INDEX IF NOT EXISTS ' + _indexUniqueId + ' ON ' + _tableName + ' ' + IndexDefinition));

For your case, if your have 2 cols, (A and B) and if you are using only A to query on your table, then you need only one index on ColA, and above IndexDefinition will be equal to : (A)

Moreover, check that officiel sqlite doc to understand how index are managed : https://www.sqlite.org/lang_createindex.html

Update to ionic RC5

If you have not done it yet, do it. There huge improvements on scrolling ng-repeat on 1.0.0-rc5

Else

If those information does not work, please provide more info on your issue : - is the list unscrollable ? or delays a lot before displaying ? or both ?

Okay, so I used the collection-repeat instead of ng-repeat in my template where the list was being generated. Dramatically increased the performance of the list. I hope this helps someone as it was driving me crazy!