Browse Source

Use zlib to compress the cache.

Heikki Hokkanen 17 years ago
parent
commit
29ef55792b
1 changed files with 10 additions and 2 deletions
  1. 10
    2
      gitstats

+ 10
- 2
gitstats View File

10
 import shutil
10
 import shutil
11
 import sys
11
 import sys
12
 import time
12
 import time
13
+import zlib
13
 
14
 
14
 GNUPLOT_COMMON = 'set terminal png transparent\nset size 0.5,0.5\n'
15
 GNUPLOT_COMMON = 'set terminal png transparent\nset size 0.5,0.5\n'
15
 
16
 
68
 			return
69
 			return
69
 		print 'Loading cache...'
70
 		print 'Loading cache...'
70
 		f = open(cachefile)
71
 		f = open(cachefile)
71
-		self.cache = pickle.load(f)
72
+		try:
73
+			self.cache = pickle.loads(zlib.decompress(f.read()))
74
+		except:
75
+			# temporary hack to upgrade non-compressed caches
76
+			f.seek(0)
77
+			self.cache = pickle.load(f)
72
 		f.close()
78
 		f.close()
73
 	
79
 	
74
 	##
80
 	##
121
 	def saveCache(self, dir):
127
 	def saveCache(self, dir):
122
 		print 'Saving cache...'
128
 		print 'Saving cache...'
123
 		f = open(os.path.join(dir, '.git', 'gitstats.cache'), 'w')
129
 		f = open(os.path.join(dir, '.git', 'gitstats.cache'), 'w')
124
-		pickle.dump(self.cache, f)
130
+		#pickle.dump(self.cache, f)
131
+		data = zlib.compress(pickle.dumps(self.cache))
132
+		f.write(data)
125
 		f.close()
133
 		f.close()
126
 
134
 
127
 class GitDataCollector(DataCollector):
135
 class GitDataCollector(DataCollector):