Commits

TK Soh  committed 94aa561

make icon overlay cache expire in 1000 ticks

  • Participants
  • Parent commits bdcf067

Comments (0)

Files changed (1)

File tortoise/iconoverlay.py

 # Copyright (C) 2007 Henry Ludemann <misc@hl.id.au>
 
 import os.path
+import win32api
 from win32com.shell import shell, shellcon
 import _winreg
 
 NOT_IN_TREE = "not in tree"
 CONTROL_FILE = "control file"
 
+CACHE_TIMEOUT = 1000
+
 class IconOverlayExtension(object):
     """
     Class to implement icon overlays for source controlled files.
     counter = 0
     last_path = ""
     last_status = UNKNOWN
+    last_tick = 0
     
     _com_interfaces_ = [shell.IID_IShellIconOverlayIdentifier]
     _public_methods_ = [
             IconOverlayExtension.counter += 1
         print "counter = %d" % IconOverlayExtension.counter
         
-        # check if path is cached
-        if IconOverlayExtension.last_path == path:
-            return IconOverlayExtension.last_status
-            
         if os.path.isdir(path):
             print "%s: skip directory" % path
             return NOT_IN_TREE      # ignore directories (for efficiency)
-            
+
+        # check if path is cached
+        tc = win32api.GetTickCount()
+        elapsed = tc - IconOverlayExtension.last_tick
+        if IconOverlayExtension.last_path == path and elapsed < CACHE_TIMEOUT:
+            return IconOverlayExtension.last_status
+
         from mercurial import hg, repo, ui, cmdutil
 
         # open repo
             # cached path and status
             IconOverlayExtension.last_status = NOT_IN_TREE
             IconOverlayExtension.last_path = path
+            IconOverlayExtension.last_tick = tc
             return NOT_IN_TREE
 
         # get file status
         else:
             status = UNKNOWN
 
-        # cached path and status
+        # cached file info
         IconOverlayExtension.last_status = status
         IconOverlayExtension.last_path = path
+        IconOverlayExtension.last_tick = tc
 
         print "%s: %s" % (path, status)
         return status