Plugins: allow returning multiple movies per callback invocation
[cinaest] / src / plugins / catalog-sqlite.vala
index be05605..c2bfbbc 100644 (file)
@@ -20,6 +20,8 @@ using Sqlite;
 
 class CatalogSqlite : Object {
        Database db;
+       SList<Movie> result;
+       int results_waiting;
 
        public delegate void ReceiveMovieFunction (string title, int year, int rating, int genres);
 
@@ -235,6 +237,9 @@ class CatalogSqlite : Object {
                        return 1;
                }
 
+               result = new SList<Movie> ();
+               results_waiting = 0;
+
                do {
                        Idle.add (query.callback);
                        yield;
@@ -247,10 +252,19 @@ class CatalogSqlite : Object {
                                movie.genres.field = stmt.column_int (3);
                                // TODO - depending on settings, this could be something else, like director info or runtime
                                movie.secondary = movie.genres.to_string ();
-                               callback (movie);
+                               result.append (movie);
+                               if (++results_waiting >= 10) {
+                                       callback (result);
+                                       result = new SList<Movie> ();
+                                       results_waiting = 0;
+                               }
                        }
                } while (rc == Sqlite.ROW);
 
+               if (results_waiting > 0)
+                       callback (result);
+               result = new SList<Movie> ();
+
                db.progress_handler (0, null);
                return 0;
        }