OSDN Git Service

Add connection throttling to try and reduce indexing & synchronizing impact.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / threads / SaveRunner.java
index 9efbd1a..a93fd17 100644 (file)
@@ -29,6 +29,7 @@ import com.trolltech.qt.core.QObject;
 \r
 import cx.fbn.nevernote.Global;\r
 import cx.fbn.nevernote.evernote.EnmlConverter;\r
+import cx.fbn.nevernote.signals.NoteSignal;\r
 import cx.fbn.nevernote.sql.DatabaseConnection;\r
 import cx.fbn.nevernote.utilities.ApplicationLogger;\r
 import cx.fbn.nevernote.utilities.Pair;\r
@@ -36,10 +37,11 @@ import cx.fbn.nevernote.utilities.Pair;
 public class SaveRunner extends QObject implements Runnable {\r
         \r
        private final ApplicationLogger         logger;\r
-       private volatile boolean                        keepRunning;\r
+       public volatile boolean                         keepRunning;\r
        public QMutex                                           threadLock;\r
        private final DatabaseConnection        conn;\r
        private boolean                                         idle;\r
+       public NoteSignal                                       noteSignals;\r
 \r
        private volatile LinkedBlockingQueue<Pair<String, String>> workQueue = new LinkedBlockingQueue<Pair<String, String>>();\r
        \r
@@ -49,9 +51,10 @@ public class SaveRunner extends QObject implements Runnable {
        //*********************************************\r
        public SaveRunner(String logname, String u, String uid, String pswd, String cpswd) {\r
                logger = new ApplicationLogger(logname);\r
-               conn = new DatabaseConnection(logger, u, uid, pswd, cpswd);\r
+               conn = new DatabaseConnection(logger, u, uid, pswd, cpswd, 0);\r
                threadLock = new QMutex();\r
                keepRunning = true;\r
+               noteSignals = new NoteSignal();\r
        }\r
        \r
        \r
@@ -136,14 +139,15 @@ public class SaveRunner extends QObject implements Runnable {
                EnmlConverter enml = new EnmlConverter(logger);\r
                String newContent = enml.convert(guid, content);\r
                String fixedContent = enml.fixEnXMLCrap(newContent);\r
-               conn.getNoteTable().updateNoteContent(guid, fixedContent);\r
-\r
-\r
-               logger.log(logger.EXTREME, "Saving new note resources");\r
-               List<Resource> oldResources = conn.getNoteTable().noteResourceTable.getNoteResources(guid, false);\r
-               List<String> newResources = enml.getResources();\r
-               removeObsoleteResources(oldResources, newResources);\r
-               \r
+               if (fixedContent != null) {\r
+                       conn.getNoteTable().updateNoteContent(guid, fixedContent);\r
+                       logger.log(logger.EXTREME, "Saving new note resources");\r
+                       List<Resource> oldResources = conn.getNoteTable().noteResourceTable.getNoteResources(guid, false);\r
+                       List<String> newResources = enml.getResources();\r
+                       removeObsoleteResources(oldResources, newResources);\r
+               } else {\r
+                       noteSignals.noteSaveRunnerError.emit(guid, null);\r
+               }\r
                logger.log(logger.HIGH, "Leaving ListManager.updateNoteContent");\r
        }\r
        \r