OSDN Git Service

- Gui cleanup - Rework count threads to reduce SQL overhead & improve performance.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / sql / NotebookTable.java
index 3cf3ab0..85ce7fb 100644 (file)
@@ -46,6 +46,7 @@ public class NotebookTable {
        private final ApplicationLogger                 logger;\r
        DatabaseConnection                                              db;\r
        private final String                                    dbName;\r
+       NSqlQuery                                                               notebookCountQuery;\r
        \r
        // Constructor\r
        public NotebookTable(ApplicationLogger l, DatabaseConnection d) {\r
@@ -671,16 +672,19 @@ public class NotebookTable {
        // Get a note tag counts\r
        public List<Pair<String,Integer>> getNotebookCounts() {\r
                List<Pair<String,Integer>> counts = new ArrayList<Pair<String,Integer>>();              \r
-               NSqlQuery query = new NSqlQuery(db.getConnection());\r
-               if (!query.exec("select notebookGuid, count(guid) from note where active=1 group by notebookguid;")) {\r
+               if (notebookCountQuery == null) {\r
+                       notebookCountQuery = new NSqlQuery(db.getConnection());\r
+                       notebookCountQuery.prepare("select notebookGuid, count(guid) from note where active=1 group by notebookguid;");\r
+               }\r
+               if (!notebookCountQuery.exec()) {\r
                        logger.log(logger.EXTREME, "NoteTags SQL getTagCounts has failed.");\r
-                       logger.log(logger.MEDIUM, query.lastError());\r
+                       logger.log(logger.MEDIUM, notebookCountQuery.lastError());\r
                        return null;\r
                }\r
-               while (query.next()) {\r
+               while (notebookCountQuery.next()) {\r
                        Pair<String,Integer> newCount = new Pair<String,Integer>();\r
-                       newCount.setFirst(query.valueString(0));\r
-                       newCount.setSecond(query.valueInteger(1));\r
+                       newCount.setFirst(notebookCountQuery.valueString(0));\r
+                       newCount.setSecond(notebookCountQuery.valueInteger(1));\r
                        counts.add(newCount);\r
                }       \r
                return counts;\r