[pitivi] previewers: Periodically save clip thumbnails



commit ddcee62ec0bbac753632e0a9888bd6ef8d0dffde
Author: Jean-François Fortin Tam <nekohayo gmail com>
Date:   Mon May 27 22:36:32 2013 -0400

    previewers: Periodically save clip thumbnails
    
    This improves perceived performance by saving "work in progress" thumbnailing.
    Otherwise, long clips might never have a saved thumbnail cache.

 pitivi/timeline/previewers.py |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
---
diff --git a/pitivi/timeline/previewers.py b/pitivi/timeline/previewers.py
index dd54772..d4f4b8b 100644
--- a/pitivi/timeline/previewers.py
+++ b/pitivi/timeline/previewers.py
@@ -25,6 +25,7 @@ import os
 import sqlite3
 import sys
 import xdg.BaseDirectory as xdg_dirs
+from random import randrange
 
 from gi.repository import Clutter, Gst, GLib, GdkPixbuf, Cogl
 from pitivi.utils.loggable import Loggable
@@ -147,6 +148,11 @@ class VideoPreviewer(Clutter.ScrollActor, Zoomable, Loggable):
             current_time += self.thumb_period
 
         GLib.idle_add(self._create_next_thumb, priority=GLib.PRIORITY_LOW)
+        # Save periodically to avoid the common situation where the user exits
+        # the app before a long clip has been fully thumbnailed.
+        # Spread timeouts between 30-80 secs to avoid concurrent disk writes.
+        random_time = randrange(30, 80)
+        GLib.timeout_add_seconds(random_time, self._autosave)
 
     def _create_next_thumb(self):
         if not self.queue:
@@ -168,6 +174,14 @@ class VideoPreviewer(Clutter.ScrollActor, Zoomable, Loggable):
             Gst.SeekType.SET, time,
             Gst.SeekType.NONE, -1)
 
+    def _autosave(self):
+        if self.queue:
+            self.log("Periodic thumbnail autosave")
+            self.thumb_cache.commit()
+            return True
+        else:
+            return False  # Stop the timer
+
     def _addVisibleThumbnails(self):
         """
         Get the thumbnails to be displayed in the currently visible clip portion


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]