flyson
flyso****@users*****
2005年 11月 13日 (日) 04:13:16 JST
Index: bbs2chreader/content/bbs2chreader/board-items.js diff -u bbs2chreader/content/bbs2chreader/board-items.js:1.11 bbs2chreader/content/bbs2chreader/board-items.js:1.12 --- bbs2chreader/content/bbs2chreader/board-items.js:1.11 Tue Oct 11 22:17:31 2005 +++ bbs2chreader/content/bbs2chreader/board-items.js Sun Nov 13 04:13:16 2005 @@ -162,6 +162,7 @@ }, refresh: function(aFilterLimit, aShowDownedLogs){ + var startTime = new Date().getTime(); const NS_BBS2CH = this._bbs2chService.nameSpace; const STATUS_NEW = 5; @@ -183,7 +184,8 @@ // sÌðÍÉg¤³K\» var regLine; - if(this.type==this._bbs2chService.BOARD_TYPE_2CH || this.type==this._bbs2chService.BOARD_TYPE_BE2CH){ // 2ch + if(this.type==this._bbs2chService.BOARD_TYPE_2CH || + this.type==this._bbs2chService.BOARD_TYPE_BE2CH){ // 2ch regLine = /^(\d{9,10})\.dat<>(.+) ?\((\d{1,4})\)/; }else if(this.type==this._bbs2chService.BOARD_TYPE_JBBS){ // JBBS regLine = /^(\d{9,10})\.cgi,(.+) ?\((\d{1,4})\)/; @@ -256,7 +258,7 @@ this._items.push(logItemHash[i]); } } - + dump("Bbs2chBoardItems.refresh : "+ (new Date().getTime() - startTime) +"ms\n"); }, @@ -265,6 +267,23 @@ */ getLogItemHash: function(aThreadUrlSpec){ var resultHash = new Array(); + var cacheFile = this._bbs2chService.getLogFileAtURL( + this.url.resolve("cache.txt")); + var cacheUpdated = false; + var cacheContents = this._bbs2chService.readFileLine(cacheFile.path, {}); + var cacheItemHash = new Array(); + for(var i=0; i<cacheContents.length; i++){ + var cacheLine = this._bbs2chService.fromType(cacheContents[i], this.type) + cacheLine = cacheLine.split("<>"); + var cacheItem = {}; + cacheItem.datID = cacheLine[0]; + cacheItem.lastModified = cacheLine[1]; + cacheItem.count = cacheLine[2]; + cacheItem.title = cacheLine[3]; + cacheItem.id = "item-" + cacheItem.datID; + cacheItemHash[cacheItem.id] = cacheItem; + } + cacheContents = new Array(); var regIndexName = /(\d{9,10})\.idx$/i; var regTitle = /^title=(.+)/m; @@ -276,24 +295,41 @@ var file = entries.getNext().QueryInterface(Components.interfaces.nsILocalFile); if(!regIndexName.test(file.leafName)) continue; var datID = RegExp.$1; + var lastModified = file.lastModifiedTime; - var indexContent = this._bbs2chService.readFile(file.path); - indexContent = this._bbs2chService.fromType(indexContent, this.type); - var logItem = {}; logItem.datID = datID; logItem.id = "item-" + datID; logItem.number = -1; - logItem.title = regTitle.test(indexContent) ? "X" + RegExp.$1 : ""; - logItem.count = regLineCount.test(indexContent) ? RegExp.$1 : ""; - logItem.read = logItem.count; logItem.unread = 0; logItem.force = 0; logItem.makeDate = logItem.datID * 1000; logItem.url = aThreadUrlSpec + logItem.datID + "/"; - + + if(logItem.id in cacheItemHash && + cacheItemHash[logItem.id].lastModified == lastModified){ + logItem.title = cacheItemHash[logItem.id].title; + logItem.count = cacheItemHash[logItem.id].count; + logItem.read = logItem.count; + }else{ + // VKorXV idx t@Cª éÆ«ÍÇÝÞ + cacheUpdated = true; + var indexContent = this._bbs2chService.readFile(file.path); + indexContent = this._bbs2chService.fromType(indexContent, this.type); + logItem.title = regTitle.test(indexContent) ? "X" + RegExp.$1 : ""; + logItem.count = regLineCount.test(indexContent) ? RegExp.$1 : ""; + logItem.read = logItem.count; + } + + cacheContents.push(datID +"<>"+ lastModified +"<>"+ logItem.count +"<>"+ logItem.title); resultHash[logItem.id] = logItem; } + + if(cacheUpdated){ + cacheContents = cacheContents.join("\n"); + cacheContents = this._bbs2chService.toType(cacheContents, this.type); + this._bbs2chService.writeFile(cacheFile.path, cacheContents, false); + } return resultHash; },