Commit ae16ebfa authored by Timo Tegtmeier's avatar Timo Tegtmeier

Fixed feed deletion, added some logging

parent 590a6daa
...@@ -50,7 +50,7 @@ enyo.kind({ ...@@ -50,7 +50,7 @@ enyo.kind({
// Obtain database API. // Obtain database API.
this.indexedDb = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB; this.indexedDb = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB;
if(!this.indexedDb) { if(!this.indexedDb) {
this.error("DB> no indexedDB support, dying"); enyo.error("DB> no indexedDB support, dying");
return; return;
} }
...@@ -62,13 +62,13 @@ enyo.kind({ ...@@ -62,13 +62,13 @@ enyo.kind({
}, },
dbSetupFailed: function(event) { dbSetupFailed: function(event) {
this.error("DB> error setting up database, code:", event.target.errorCode); enyo.error("DB> error setting up database, code:", event.target.errorCode);
}, },
dbReady: function(event, request) { dbReady: function(event, request) {
this.db = event.result; this.db = event.result;
this.log("DB> Database schema ready"); enyo.log("DB> Database schema ready");
enyo.asyncMethod(function() { enyo.asyncMethod(function() {
if(enyo.application.prefs.updateOnStart || enyo.application.feeds.updateWhenReady) { if(enyo.application.prefs.updateOnStart || enyo.application.feeds.updateWhenReady) {
...@@ -194,7 +194,7 @@ enyo.kind({ ...@@ -194,7 +194,7 @@ enyo.kind({
* @param event * @param event
*/ */
transactionFailed: function(event) { transactionFailed: function(event) {
this.error("DB> transaction failed, code:", event.target.errorCode); enyo.error("DB> transaction failed, code:", event.target.errorCode);
}, },
/** @private /** @private
...@@ -211,7 +211,7 @@ enyo.kind({ ...@@ -211,7 +211,7 @@ enyo.kind({
* *
*/ */
errorHandler: function(event) { errorHandler: function(event) {
this.error("DB> query failed"); enyo.error("DB> query failed");
}, },
/** @private /** @private
...@@ -278,7 +278,7 @@ enyo.kind({ ...@@ -278,7 +278,7 @@ enyo.kind({
onSuccess = onSuccess || this.nullData; onSuccess = onSuccess || this.nullData;
onFail = onFail || this.errorHandler; onFail = onFail || this.errorHandler;
this.log("DB> deleting category", category.id); enyo.log("DB> deleting category", category.id);
// Open transaction. // Open transaction.
var transaction = this.writeTransaction(["categories", "feeds", "stories"], onSuccess, onFail); var transaction = this.writeTransaction(["categories", "feeds", "stories"], onSuccess, onFail);
...@@ -445,8 +445,16 @@ enyo.kind({ ...@@ -445,8 +445,16 @@ enyo.kind({
* @param feed feed to update * @param feed feed to update
*/ */
doUpdateFeedCount: function(feeds, deltaUnRead, deltaNew, feed) { doUpdateFeedCount: function(feeds, deltaUnRead, deltaNew, feed) {
feed.numUnRead += deltaUnRead; feed.numUnRead += deltaUnRead;
feed.numNew += deltaNew; feed.numNew += deltaNew;
enyo.log("DB> Updating feed", feed.title, ": deltaUnread:", deltaUnRead, "deltaNew:", deltaNew, "counts:",
feed.numNew, feed.numUnRead);
if((feed.numNew < 0) || (feed.numUnRead < 0)) {
enyo.warn("DB> LOGIC ERROR FOUND! Feed", feed.title, "to be updated in improper way, counts:",
feed.numNew, feed.numUnRead);
}
feeds.put(feed); feeds.put(feed);
}, },
...@@ -466,22 +474,37 @@ enyo.kind({ ...@@ -466,22 +474,37 @@ enyo.kind({
var stories = transaction.objectStore("stories"); var stories = transaction.objectStore("stories");
var feeds = transaction.objectStore("feeds"); var feeds = transaction.objectStore("feeds");
var starredNew = 0;
var starredUnread = 0;
function updateFeed(event) { function updateFeed(event) {
var oldFeed = event.target.result; var oldFeed = event.target.result;
// Update feed aggregations. // Update feed aggregations.
var feedupdater = enyo.bind(self, self.updateFeedCount, feeds, -oldFeed.numUnRead, -oldFeed.numNew); feeds.index("feedType")
feeds.index("feedType").get(feedTypes.ftAllItems).onsuccess = feedupdater; .get(feedTypes.ftAllItems)
feeds.index("feedType").get(feedTypes.ftStarred).onsuccess = feedupdater; .onsuccess = enyo.bind(self, self.updateFeedCount, feeds, -oldFeed.numUnRead, -oldFeed.numNew);
if((starredNew > 0) || (starredUnread > 0)) {
// Delete feed. feeds.index("feedType")
.get(feedTypes.ftStarred)
.onsuccess = enyo.bind(self, self.updateFeedCount, feeds, -starredUnread, -starredNew);
}
// Delete feed.
feeds.delete(feed.id); feeds.delete(feed.id);
} }
stories.index("fid").openCursor(this.boundOnly(feed.id)).onsuccess = function(event) { stories.index("fid").openCursor(this.boundOnly(feed.id)).onsuccess = function(event) {
var cursor = event.target.result; var cursor = event.target.result;
if(cursor) { if(cursor) {
stories.delete(cursor.value.id); var story = cursor.value;
if(story.isStarred) {
if(story.isNew)
starredNew++;
if(!story.isRead)
starredUnread++;
}
stories.delete(story.id);
cursor.continue(); cursor.continue();
} else { } else {
feeds.get(feed.id).onsuccess = updateFeed; feeds.get(feed.id).onsuccess = updateFeed;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment