Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/jangernert/FeedReader.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrendan Long <self@brendanlong.com>2019-01-29 02:31:02 +0300
committerBrendan Long <self@brendanlong.com>2019-01-29 02:35:13 +0300
commit9194a3b74d7e262a0869c874483af366bf26da68 (patch)
tree07177bd49ab57c18757e03ab4e6f32a774eb1443
parent89ddf05ad3cd6245c9a7b51150f2455b96768df9 (diff)
Re-use databases in the most obvious (single function) cases
These cases don't involve any threading so this should speed things up a little without any risk.
-rw-r--r--plugins/backend/bazqux/bazquxAPI.vala6
-rw-r--r--plugins/backend/bazqux/bazquxInterface.vala5
-rw-r--r--plugins/backend/decsync/decsyncInterface.vala22
-rw-r--r--plugins/backend/decsync/decsyncListeners.vala10
-rw-r--r--plugins/backend/feedbin/feedbinInterface.vala6
-rw-r--r--plugins/backend/feedhq/feedhqInterface.vala5
-rw-r--r--plugins/backend/feedly/feedlyAPI.vala13
-rw-r--r--plugins/backend/feedly/feedlyInterface.vala5
-rw-r--r--plugins/backend/inoreader/InoReaderAPI.vala6
-rw-r--r--plugins/backend/inoreader/InoReaderInterface.vala5
-rw-r--r--plugins/backend/local/localInterface.vala17
-rw-r--r--plugins/backend/oldreader/oldreaderAPI.vala3
-rw-r--r--plugins/backend/oldreader/oldreaderInterface.vala5
-rw-r--r--plugins/backend/ttrss/ttrssAPI.vala3
-rw-r--r--plugins/backend/ttrss/ttrssInterface.vala11
-rw-r--r--src/ActionCache.vala10
-rw-r--r--src/Backend/Backend.vala29
-rw-r--r--src/Backend/FeedServer.vala60
-rw-r--r--src/CachedActionManager.vala14
-rw-r--r--src/Utils.vala13
-rw-r--r--src/Widgets/FeedList.vala24
-rw-r--r--src/Widgets/MainWindow.vala5
-rw-r--r--src/Widgets/TagPopover.vala3
23 files changed, 165 insertions, 115 deletions
diff --git a/plugins/backend/bazqux/bazquxAPI.vala b/plugins/backend/bazqux/bazquxAPI.vala
index 9a16e1ae..8b203ab7 100644
--- a/plugins/backend/bazqux/bazquxAPI.vala
+++ b/plugins/backend/bazqux/bazquxAPI.vala
@@ -162,6 +162,7 @@ public bool getCategoriesAndTags(Gee.List<Feed> feeds, Gee.List<Category> catego
uint length = array.get_length();
int orderID = 0;
+ var db = DataBase.readOnly();
for (uint i = 0; i < length; i++)
{
Json.Object object = array.get_object_element(i);
@@ -191,7 +192,7 @@ public bool getCategoriesAndTags(Gee.List<Feed> feeds, Gee.List<Category> catego
new Tag(
id,
title,
- DataBase.readOnly().getTagColor()
+ db.getTagColor()
)
);
}
@@ -323,6 +324,7 @@ public string? getArticles(Gee.List<Article> articles, int count, ArticleStatus
var array = root.get_array_member("items");
uint length = array.get_length();
+ var db = DataBase.readOnly();
for (uint i = 0; i < length; i++)
{
Json.Object object = array.get_object_element(i);
@@ -341,7 +343,7 @@ public string? getArticles(Gee.List<Article> articles, int count, ArticleStatus
marked = true;
else if(cat.has_suffix("com.google/read"))
read = true;
- else if(cat.contains("/label/") && DataBase.readOnly().getTagName(cat) != null)
+ else if(cat.contains("/label/") && db.getTagName(cat) != null)
tags.add(cat);
}
diff --git a/plugins/backend/bazqux/bazquxInterface.vala b/plugins/backend/bazqux/bazquxInterface.vala
index 708fc8de..479c12c5 100644
--- a/plugins/backend/bazqux/bazquxInterface.vala
+++ b/plugins/backend/bazqux/bazquxInterface.vala
@@ -257,13 +257,14 @@ public void setCategoryRead(string catID)
public void markAllItemsRead()
{
- var categories = DataBase.readOnly().read_categories();
+ var db = DataBase.readOnly();
+ var categories = db.read_categories();
foreach(Category cat in categories)
{
m_api.markAsRead(cat.getCatID());
}
- var feeds = DataBase.readOnly().read_feeds_without_cat();
+ var feeds = db.read_feeds_without_cat();
foreach(Feed feed in feeds)
{
m_api.markAsRead(feed.getFeedID());
diff --git a/plugins/backend/decsync/decsyncInterface.vala b/plugins/backend/decsync/decsyncInterface.vala
index baa406c9..23303f1e 100644
--- a/plugins/backend/decsync/decsyncInterface.vala
+++ b/plugins/backend/decsync/decsyncInterface.vala
@@ -302,9 +302,10 @@ public void setArticleIsRead(string articleIDs, ArticleStatus readStatus)
var read = readStatus == ArticleStatus.READ;
Logger.debug("Mark " + articleIDs + " as " + (read ? "read" : "unread"));
var entries = new Gee.ArrayList<Decsync.EntryWithPath>();
+ var db = DataBase.readOnly();
foreach (var articleID in articleIDs.split(","))
{
- Article? article = DataBase.readOnly().read_article(articleID);
+ Article? article = db.read_article(articleID);
if (article != null)
{
var path = articleToPath(article, "read");
@@ -380,12 +381,13 @@ public bool addFeed(string feedURL, string? catID, string? newCatName, out strin
public bool addFeedWithDecsync(string feedURL, string? catID, string? newCatName, out string feedID, out string errmsg, bool updateDecsync = true)
{
+ var db = DataBase.writeAccess();
var catIDs = new Gee.ArrayList<string>();
if(catID == null && newCatName != null)
{
string cID = createCategory(newCatName, null);
var cat = new Category(cID, newCatName, 0, 99, CategoryID.MASTER.to_string(), 1);
- DataBase.writeAccess().write_categories(ListUtils.single(cat));
+ db.write_categories(ListUtils.single(cat));
catIDs.add(cID);
}
else if(catID != null && newCatName == null)
@@ -404,8 +406,8 @@ public bool addFeedWithDecsync(string feedURL, string? catID, string? newCatName
if(feed != null)
{
- if(!DataBase.readOnly().feed_exists(feed.getURL())) {
- DataBase.writeAccess().write_feeds(ListUtils.single(feed));
+ if(!db.feed_exists(feed.getURL())) {
+ db.write_feeds(ListUtils.single(feed));
if (updateDecsync)
{
@@ -455,8 +457,9 @@ public void moveFeed(string feedID, string newCatID, string? currentCatID)
public string createCategory(string title, string? parentID)
{
- string? catID = DataBase.readOnly().getCategoryID(title);
- while (catID == null || DataBase.readOnly().read_category(catID) != null)
+ var db = DataBase.readOnly();
+ string? catID = db.getCategoryID(title);
+ while (catID == null || db.read_category(catID) != null)
{
catID = "catID%05d".printf(Random.int_range(0, 100000));
}
@@ -561,6 +564,7 @@ public void getArticles(int count, ArticleStatus whatToGet, DateTime? since, str
Logger.debug("Got %u articles".printf(doc.get_items().length()));
var newArticles = new Gee.ArrayList<Article>();
+ var db = DataBase.readOnly();
foreach(Rss.Item item in doc.get_items())
{
string? articleID = item.guid;
@@ -576,9 +580,9 @@ public void getArticles(int count, ArticleStatus whatToGet, DateTime? since, str
articleID = item.link;
}
- if (DataBase.readOnly().read_article(articleID) != null)
- {
- continue;
+ if (db.read_article(articleID) != null)
+ {
+ continue;
}
var date = Rfc822.parseDate(item.pub_date);
diff --git a/plugins/backend/decsync/decsyncListeners.vala b/plugins/backend/decsync/decsyncListeners.vala
index 98006cd4..c907d240 100644
--- a/plugins/backend/decsync/decsyncListeners.vala
+++ b/plugins/backend/decsync/decsyncListeners.vala
@@ -50,7 +50,8 @@ public override void onSubdirEntryUpdate(Gee.List<string> path, Decsync.Entry en
{
Logger.debug((added ? "mark " : "unmark ") + articleID);
}
- Article? article = DataBase.readOnly().read_article(articleID);
+ var db = DataBase.writeAccess();
+ Article? article = db.read_article(articleID);
if (article == null)
{
Logger.info("Unkown article " + articleID);
@@ -64,7 +65,7 @@ public override void onSubdirEntryUpdate(Gee.List<string> path, Decsync.Entry en
{
article.setMarked(added ? ArticleStatus.MARKED : ArticleStatus.UNMARKED);
}
- DataBase.writeAccess().update_article(article);
+ db.update_article(article);
}
}
@@ -163,7 +164,8 @@ public override void onSubfileEntryUpdate(Decsync.Entry entry, Unit extra)
Logger.warning("Invalid feedID " + Json.to_string(entry.key, false));
return;
}
- var feed = DataBase.readOnly().read_feed(feedID);
+ var db = DataBase.writeAccess();
+ var feed = db.read_feed(feedID);
if (feed == null) return;
var currentCatID = feed.getCatString();
string newCatID;
@@ -181,7 +183,7 @@ public override void onSubfileEntryUpdate(Decsync.Entry entry, Unit extra)
return;
}
addCategory(m_plugin, newCatID);
- DataBase.writeAccess().move_feed(feedID, currentCatID, newCatID);
+ db.move_feed(feedID, currentCatID, newCatID);
}
}
diff --git a/plugins/backend/feedbin/feedbinInterface.vala b/plugins/backend/feedbin/feedbinInterface.vala
index 519ae931..cc6fc685 100644
--- a/plugins/backend/feedbin/feedbinInterface.vala
+++ b/plugins/backend/feedbin/feedbinInterface.vala
@@ -285,9 +285,10 @@ private void setRead(string id, FeedListType type)
{
const int count = 1000;
int num_articles = 1; // set to any value > 0
+ var db = DataBase.readOnly();
for(var offset = 0; num_articles > 0; offset += count)
{
- var articles = DataBase.readOnly().read_articles(id, type, ArticleListState.ALL, "", count, offset);
+ var articles = db.read_articles(id, type, ArticleListState.ALL, "", count, offset);
var entry_ids = new Gee.ArrayList<int64?>();
foreach(var article in articles)
{
@@ -643,6 +644,7 @@ requires (count >= 0)
{
try
{
+ var db = DataBase.readOnly();
int64? feed_id = null;
if(!is_tag_id && feed_id_str != null)
feed_id = int64.parse(feed_id_str);
@@ -683,7 +685,7 @@ requires (count >= 0)
for(var offset = 0, c = 1000; ; offset += c)
{
var articles = new Gee.ArrayList<Article>();
- var existing_articles = DataBase.readOnly().read_articles(search_feed_id, search_type, ArticleListState.ALL, "", c, offset);
+ var existing_articles = db.read_articles(search_feed_id, search_type, ArticleListState.ALL, "", c, offset);
if(existing_articles.size == 0)
break;
diff --git a/plugins/backend/feedhq/feedhqInterface.vala b/plugins/backend/feedhq/feedhqInterface.vala
index 0057e365..cf8363a3 100644
--- a/plugins/backend/feedhq/feedhqInterface.vala
+++ b/plugins/backend/feedhq/feedhqInterface.vala
@@ -259,13 +259,14 @@ public void setCategoryRead(string catID)
public void markAllItemsRead()
{
- var categories = DataBase.readOnly().read_categories();
+ var db = DataBase.readOnly();
+ var categories = db.read_categories();
foreach(Category cat in categories)
{
m_api.markAsRead(cat.getCatID());
}
- var feeds = DataBase.readOnly().read_feeds_without_cat();
+ var feeds = db.read_feeds_without_cat();
foreach(Feed feed in feeds)
{
m_api.markAsRead(feed.getFeedID());
diff --git a/plugins/backend/feedly/feedlyAPI.vala b/plugins/backend/feedly/feedlyAPI.vala
index 74123013..35c26609 100644
--- a/plugins/backend/feedly/feedlyAPI.vala
+++ b/plugins/backend/feedly/feedlyAPI.vala
@@ -271,6 +271,7 @@ public bool getTags(Gee.List<Tag> tags)
Json.Array array = parser.get_root().get_array ();
uint length = array.get_length();
+ var db = DataBase.readOnly();
for (uint i = 0; i < length; i++) {
Json.Object object = array.get_object_element(i);
@@ -278,7 +279,7 @@ public bool getTags(Gee.List<Tag> tags)
new Tag(
object.get_string_member("id"),
object.has_member("label") ? object.get_string_member("label") : "",
- DataBase.readOnly().getTagColor()
+ db.getTagColor()
)
);
}
@@ -595,9 +596,10 @@ public bool addSubscription(string feedURL, string? title = null, string? catIDs
var catArray = catIDs.split(",");
Json.Array cats = new Json.Array();
+ var db = DataBase.readOnly();
foreach(string catID in catArray)
{
- string catName = DataBase.readOnly().getCategoryName(catID);
+ string catName = db.getCategoryName(catID);
Json.Object catObject = new Json.Object();
catObject.set_string_member("id", catID);
catObject.set_string_member("label", catName);
@@ -617,7 +619,8 @@ public bool addSubscription(string feedURL, string? title = null, string? catIDs
public void moveSubscription(string feedID, string newCatID, string? oldCatID = null)
{
- var Feed = DataBase.readOnly().read_feed(feedID);
+ var db = DataBase.readOnly();
+ var Feed = db.read_feed(feedID);
Json.Object object = new Json.Object();
object.set_string_member("id", feedID);
@@ -631,7 +634,7 @@ public void moveSubscription(string feedID, string newCatID, string? oldCatID =
{
if(catID != oldCatID)
{
- string catName = DataBase.readOnly().getCategoryName(catID);
+ string catName = db.getCategoryName(catID);
Json.Object catObject = new Json.Object();
catObject.set_string_member("id", catID);
catObject.set_string_member("label", catName);
@@ -639,7 +642,7 @@ public void moveSubscription(string feedID, string newCatID, string? oldCatID =
}
}
- string newCatName = DataBase.readOnly().getCategoryName(newCatID);
+ string newCatName = db.getCategoryName(newCatID);
Json.Object catObject = new Json.Object();
catObject.set_string_member("id", newCatID);
catObject.set_string_member("label", newCatName);
diff --git a/plugins/backend/feedly/feedlyInterface.vala b/plugins/backend/feedly/feedlyInterface.vala
index d4391bc5..ec96fd7a 100644
--- a/plugins/backend/feedly/feedlyInterface.vala
+++ b/plugins/backend/feedly/feedlyInterface.vala
@@ -218,8 +218,9 @@ public void markAllItemsRead()
string catArray = "";
string feedArray = "";
- var categories = DataBase.readOnly().read_categories();
- var feeds = DataBase.readOnly().read_feeds_without_cat();
+ var db = DataBase.readOnly();
+ var categories = db.read_categories();
+ var feeds = db.read_feeds_without_cat();
foreach(Category cat in categories)
{
diff --git a/plugins/backend/inoreader/InoReaderAPI.vala b/plugins/backend/inoreader/InoReaderAPI.vala
index b179973d..7919d147 100644
--- a/plugins/backend/inoreader/InoReaderAPI.vala
+++ b/plugins/backend/inoreader/InoReaderAPI.vala
@@ -162,6 +162,7 @@ public bool getCategoriesAndTags(Gee.List<Feed> feeds, Gee.List<Category> catego
uint length = array.get_length();
int orderID = 0;
+ var db = DataBase.readOnly();
for (uint i = 0; i < length; i++)
{
Json.Object object = array.get_object_element(i);
@@ -190,7 +191,7 @@ public bool getCategoriesAndTags(Gee.List<Feed> feeds, Gee.List<Category> catego
new Tag(
id,
title,
- DataBase.readOnly().getTagColor()
+ db.getTagColor()
)
);
}
@@ -318,6 +319,7 @@ public string? getArticles(Gee.List<Article> articles, int count, ArticleStatus
var array = root.get_array_member("items");
uint length = array.get_length();
+ var db = DataBase.readOnly();
for (uint i = 0; i < length; i++)
{
Json.Object object = array.get_object_element(i);
@@ -336,7 +338,7 @@ public string? getArticles(Gee.List<Article> articles, int count, ArticleStatus
marked = true;
else if(cat.has_suffix("com.google/read"))
read = true;
- else if(cat.contains("/label/") && DataBase.readOnly().getTagName(cat) != null)
+ else if(cat.contains("/label/") && db.getTagName(cat) != null)
tags.add(cat);
}
diff --git a/plugins/backend/inoreader/InoReaderInterface.vala b/plugins/backend/inoreader/InoReaderInterface.vala
index 23ea916a..ca176530 100644
--- a/plugins/backend/inoreader/InoReaderInterface.vala
+++ b/plugins/backend/inoreader/InoReaderInterface.vala
@@ -232,13 +232,14 @@ public void setCategoryRead(string catID)
public void markAllItemsRead()
{
- var categories = DataBase.readOnly().read_categories();
+ var db = DataBase.readOnly();
+ var categories = db.read_categories();
foreach(Category cat in categories)
{
m_api.markAsRead(cat.getCatID());
}
- var feeds = DataBase.readOnly().read_feeds_without_cat();
+ var feeds = db.read_feeds_without_cat();
foreach(Feed feed in feeds)
{
m_api.markAsRead(feed.getFeedID());
diff --git a/plugins/backend/local/localInterface.vala b/plugins/backend/local/localInterface.vala
index c322af6a..7eb801ed 100644
--- a/plugins/backend/local/localInterface.vala
+++ b/plugins/backend/local/localInterface.vala
@@ -365,8 +365,9 @@ public string createTag(string caption)
{
string tagID = "1";
- if(!DataBase.readOnly().isTableEmpty("tags"))
- tagID = (int.parse(DataBase.readOnly().getMaxID("tags", "tagID")) + 1).to_string();
+ var db = DataBase.readOnly();
+ if(!db.isTableEmpty("tags"))
+ tagID = (int.parse(db.getMaxID("tags", "tagID")) + 1).to_string();
Logger.info("createTag: ID = " + tagID);
return tagID;
@@ -385,11 +386,12 @@ public void renameTag(string tagID, string title)
public bool addFeed(string feedURL, string? catID, string? newCatName, out string feedID, out string errmsg)
{
var catIDs = new Gee.ArrayList<string>();
+ var db = DataBase.writeAccess();
if(catID == null && newCatName != null)
{
string cID = createCategory(newCatName, null);
var cat = new Category(cID, newCatName, 0, 99, CategoryID.MASTER.to_string(), 1);
- DataBase.writeAccess().write_categories(ListUtils.single(cat));
+ db.write_categories(ListUtils.single(cat));
catIDs.add(cID);
}
else if(catID != null && newCatName == null)
@@ -408,8 +410,8 @@ public bool addFeed(string feedURL, string? catID, string? newCatName, out strin
if(feed != null)
{
- if(!DataBase.readOnly().feed_exists(feed.getURL())) {
- DataBase.writeAccess().write_feeds(ListUtils.single(feed));
+ if(!db.feed_exists(feed.getURL())) {
+ db.write_feeds(ListUtils.single(feed));
return true;
}
}
@@ -520,7 +522,8 @@ public int getUnreadCount()
public void getArticles(int count, ArticleStatus whatToGet, DateTime? since, string? feedID, bool isTagID, GLib.Cancellable? cancellable = null)
{
- var feeds = DataBase.readOnly().read_feeds();
+ var db = DataBase.writeAccess();
+ var feeds = db.read_feeds();
var articles = new Gee.ArrayList<Article>();
GLib.Mutex mutex = GLib.Mutex();
@@ -665,7 +668,7 @@ public void getArticles(int count, ArticleStatus whatToGet, DateTime? since, str
if(articles.size > 0)
{
- DataBase.writeAccess().write_articles(articles);
+ db.write_articles(articles);
Logger.debug("localInterface: %i articles written".printf(articles.size));
refreshFeedListCounter();
updateArticleList();
diff --git a/plugins/backend/oldreader/oldreaderAPI.vala b/plugins/backend/oldreader/oldreaderAPI.vala
index 48724ae6..a25b6bd2 100644
--- a/plugins/backend/oldreader/oldreaderAPI.vala
+++ b/plugins/backend/oldreader/oldreaderAPI.vala
@@ -300,6 +300,7 @@ public string? getArticles(Gee.List<Article> articles, int count, ArticleStatus
var array = root.get_array_member("items");
uint length = array.get_length();
+ var db = DataBase.readOnly();
for (uint i = 0; i < length; i++)
{
Json.Object object = array.get_object_element(i);
@@ -318,7 +319,7 @@ public string? getArticles(Gee.List<Article> articles, int count, ArticleStatus
marked = true;
else if(cat.has_suffix("com.google/read"))
read = true;
- else if(cat.contains("/label/") && DataBase.readOnly().getTagName(cat) != null)
+ else if(cat.contains("/label/") && db.getTagName(cat) != null)
tags.add(cat);
}
diff --git a/plugins/backend/oldreader/oldreaderInterface.vala b/plugins/backend/oldreader/oldreaderInterface.vala
index 0567fd6e..5993f55b 100644
--- a/plugins/backend/oldreader/oldreaderInterface.vala
+++ b/plugins/backend/oldreader/oldreaderInterface.vala
@@ -258,13 +258,14 @@ public void setCategoryRead(string catID)
public void markAllItemsRead()
{
- var categories = DataBase.readOnly().read_categories();
+ var db = DataBase.readOnly();
+ var categories = db.read_categories();
foreach(Category cat in categories)
{
m_api.markAsRead(cat.getCatID());
}
- var feeds = DataBase.readOnly().read_feeds_without_cat();
+ var feeds = db.read_feeds_without_cat();
foreach(Feed feed in feeds)
{
m_api.markAsRead(feed.getFeedID());
diff --git a/plugins/backend/ttrss/ttrssAPI.vala b/plugins/backend/ttrss/ttrssAPI.vala
index b5e26aab..8a2f31c6 100644
--- a/plugins/backend/ttrss/ttrssAPI.vala
+++ b/plugins/backend/ttrss/ttrssAPI.vala
@@ -298,6 +298,7 @@ public bool getTags(Gee.List<Tag> tags)
var response = message.get_response_array();
var tag_count = response.get_length();
+ var db = DataBase.readOnly();
for(uint i = 0; i < tag_count; ++i)
{
var tag_node = response.get_object_element(i);
@@ -305,7 +306,7 @@ public bool getTags(Gee.List<Tag> tags)
new Tag(
tag_node.get_int_member("id").to_string(),
tag_node.get_string_member("caption"),
- DataBase.readOnly().getTagColor()
+ db.getTagColor()
)
);
}
diff --git a/plugins/backend/ttrss/ttrssInterface.vala b/plugins/backend/ttrss/ttrssInterface.vala
index 1e1c1d7d..fb226416 100644
--- a/plugins/backend/ttrss/ttrssInterface.vala
+++ b/plugins/backend/ttrss/ttrssInterface.vala
@@ -468,12 +468,13 @@ public void getArticles(int count, ArticleStatus whatToGet, DateTime? since, str
if(cancellable != null && cancellable.is_cancelled())
return;
+ var db = DataBase.writeAccess();
if(unreadIDs != null && whatToGet == ArticleStatus.ALL)
{
Logger.debug("getArticles: newsplus plugin active");
var markedIDs = m_api.NewsPlus(ArticleStatus.MARKED, settings_general.get_int("max-articles"));
- DataBase.writeAccess().updateArticlesByID(unreadIDs, "unread");
- DataBase.writeAccess().updateArticlesByID(markedIDs, "marked");
+ db.updateArticlesByID(unreadIDs, "unread");
+ db.updateArticlesByID(markedIDs, "marked");
//updateArticleList();
}
@@ -505,14 +506,14 @@ public void getArticles(int count, ArticleStatus whatToGet, DateTime? since, str
// only update article states if they haven't been updated by the newsPlus-plugin
if(unreadIDs == null || whatToGet != ArticleStatus.ALL)
{
- DataBase.writeAccess().update_articles(articles);
+ db.update_articles(articles);
updateArticleList();
}
foreach(Article article in articles)
{
var id = article.getArticleID();
- if(!DataBase.readOnly().article_exists(id))
+ if(!db.article_exists(id))
{
articleIDs += id + ",";
}
@@ -536,7 +537,7 @@ public void getArticles(int count, ArticleStatus whatToGet, DateTime? since, str
if(articles.size > 0)
{
- DataBase.writeAccess().write_articles(articles);
+ db.write_articles(articles);
refreshFeedListCounter();
updateArticleList();
}
diff --git a/src/ActionCache.vala b/src/ActionCache.vala
index aa892014..36413376 100644
--- a/src/ActionCache.vala
+++ b/src/ActionCache.vala
@@ -119,12 +119,15 @@ private void removeOpposite(CachedAction action)
private void removeForFeed(string feedID)
{
+ DataBaseReadOnly db = null;
foreach(CachedAction a in m_list)
{
if(a.getType() == CachedActions.MARK_READ
|| a.getType() == CachedActions.MARK_UNREAD)
{
- if(feedID == DataBase.readOnly().getFeedIDofArticle(a.getID()))
+ if (db == null)
+ db = DataBase.readOnly();
+ if(feedID == db.getFeedIDofArticle(a.getID()))
{
m_list.remove(a);
}
@@ -204,6 +207,7 @@ public ArticleStatus checkRead(Article a)
}
else if(a.getUnread() == ArticleStatus.UNREAD)
{
+ DataBaseReadOnly db = null;
foreach(CachedAction action in m_list)
{
switch(action.getType())
@@ -217,7 +221,9 @@ public ArticleStatus checkRead(Article a)
break;
case CachedActions.MARK_READ_CATEGORY:
- var feedIDs = DataBase.readOnly().getFeedIDofCategorie(a.getArticleID());
+ if (db == null)
+ db = DataBase.readOnly();
+ var feedIDs = db.getFeedIDofCategorie(a.getArticleID());
foreach(string feedID in feedIDs)
{
if(feedID == a.getFeedID())
diff --git a/src/Backend/Backend.vala b/src/Backend/Backend.vala
index 4f426963..a60197f7 100644
--- a/src/Backend/Backend.vala
+++ b/src/Backend/Backend.vala
@@ -437,15 +437,16 @@ public void tagArticle(Article article, Tag tag, bool add)
article.removeTag(tag.getTagID());
}
- DataBase.writeAccess().update_article(article);
+ var db = DataBase.writeAccess();
+ db.update_article(article);
- if(!add && !DataBase.readOnly().tag_still_used(tag))
+ if(!add && !db.tag_still_used(tag))
{
Logger.debug("backend: remove tag completely");
asyncPayload pl2 = () => { FeedServer.get_default().deleteTag(tag.getTagID()); };
callAsync.begin((owned)pl2, (obj, res) => { callAsync.end(res); });
- asyncPayload pl3 = () => { DataBase.writeAccess().dropTag(tag); };
+ asyncPayload pl3 = () => { db.dropTag(tag); };
callAsync.begin((owned)pl3, (obj, res) => {
callAsync.end(res);
newFeedList();
@@ -494,8 +495,9 @@ public void updateTagColor(Tag tag)
public void resetDB()
{
- DataBase.writeAccess().resetDB();
- DataBase.writeAccess().init();
+ var db = DataBase.writeAccess();
+ db.resetDB();
+ db.init();
}
public void resetAccount()
@@ -642,7 +644,8 @@ public void markAllItemsRead()
public void removeCategory(string catID)
{
- var feeds = DataBase.readOnly().read_feeds();
+ var db = DataBase.writeAccess();
+ var feeds = db.read_feeds();
foreach(Feed feed in feeds)
{
if(feed.hasCat(catID))
@@ -651,7 +654,7 @@ public void removeCategory(string catID)
}
}
- var cats = DataBase.readOnly().read_categories(feeds);
+ var cats = db.read_categories(feeds);
foreach(var cat in cats)
{
if(cat.getParent() == catID)
@@ -663,7 +666,7 @@ public void removeCategory(string catID)
asyncPayload pl = () => { FeedServer.get_default().deleteCategory(catID); };
callAsync.begin((owned)pl, (obj, res) => { callAsync.end(res); });
- asyncPayload pl2 = () => { DataBase.writeAccess().delete_category(catID); };
+ asyncPayload pl2 = () => { db.delete_category(catID); };
callAsync.begin((owned)pl2, (obj, res) => {
callAsync.end(res);
newFeedList();
@@ -691,20 +694,21 @@ public string addCategory(string title, string? parentID = null, bool createLoca
{
string? parent = parentID;
int level = 1;
+ var db = DataBase.writeAccess();
if(parentID == null || parentID == "")
{
parent = CategoryID.MASTER.to_string();
}
else
{
- var parentCat = DataBase.readOnly().read_category(parentID);
+ var parentCat = db.read_category(parentID);
level = parentCat.getLevel()+1;
}
var cat = new Category(catID, title, 0, 99, parent, level);
var list = new Gee.LinkedList<Category>();
list.add(cat);
- DataBase.writeAccess().write_categories(list);
+ db.write_categories(list);
}
return catID;
@@ -712,10 +716,11 @@ public string addCategory(string title, string? parentID = null, bool createLoca
public void removeCategoryWithChildren(string catID)
{
- var feeds = DataBase.readOnly().read_feeds();
+ var db = DataBase.readOnly();
+ var feeds = db.read_feeds();
deleteFeedsInCategory(catID, feeds);
- var cats = DataBase.readOnly().read_categories(feeds);
+ var cats = db.read_categories(feeds);
foreach(var cat in cats)
{
if(cat.getParent() == catID)
diff --git a/src/Backend/FeedServer.vala b/src/Backend/FeedServer.vala
index 2ee30bae..58ef831e 100644
--- a/src/Backend/FeedServer.vala
+++ b/src/Backend/FeedServer.vala
@@ -174,6 +174,7 @@ public void syncContent(GLib.Cancellable? cancellable = null)
return;
}
+ var db = DataBase.writeAccess();
if(syncFeedsAndCategories())
{
var categories = new Gee.LinkedList<Category>();
@@ -198,21 +199,21 @@ public void syncContent(GLib.Cancellable? cancellable = null)
return;
// write categories
- DataBase.writeAccess().reset_exists_flag();
- DataBase.writeAccess().write_categories(categories);
- DataBase.writeAccess().delete_nonexisting_categories();
+ db.reset_exists_flag();
+ db.write_categories(categories);
+ db.delete_nonexisting_categories();
// write feeds
- DataBase.writeAccess().reset_subscribed_flag();
- DataBase.writeAccess().write_feeds(feeds);
- DataBase.writeAccess().delete_articles_without_feed();
- DataBase.writeAccess().delete_unsubscribed_feeds();
+ db.reset_subscribed_flag();
+ db.write_feeds(feeds);
+ db.delete_articles_without_feed();
+ db.delete_unsubscribed_feeds();
// write tags
- DataBase.writeAccess().reset_exists_tag();
- DataBase.writeAccess().write_tags(tags);
- DataBase.writeAccess().update_tags(tags);
- DataBase.writeAccess().delete_nonexisting_tags();
+ db.reset_exists_tag();
+ db.write_tags(tags);
+ db.update_tags(tags);
+ db.delete_nonexisting_tags();
FeedReaderBackend.get_default().newFeedList();
}
@@ -222,7 +223,7 @@ public void syncContent(GLib.Cancellable? cancellable = null)
var drop_articles = (DropArticles)Settings.general().get_enum("drop-articles-after");
DateTime? since = drop_articles.to_start_date();
- if(!DataBase.readOnly().isTableEmpty("articles"))
+ if(!db.isTableEmpty("articles"))
{
var last_sync = new DateTime.from_unix_utc(Settings.state().get_int("last-sync"));
if(since == null || last_sync.to_unix() > since.to_unix())
@@ -236,7 +237,7 @@ public void syncContent(GLib.Cancellable? cancellable = null)
syncProgress(_("Getting articles"));
- string row_id = DataBase.readOnly().getMaxID("articles", "rowid");
+ string row_id = db.getMaxID("articles", "rowid");
int before = row_id != null ? int.parse(row_id) : 0;
if(unread > max && useMaxArticles())
@@ -253,10 +254,10 @@ public void syncContent(GLib.Cancellable? cancellable = null)
return;
//update fulltext table
- DataBase.writeAccess().updateFTS();
+ db.updateFTS();
- int new_and_unread = DataBase.readOnly().get_new_unread_count(row_id != null ? int.parse(row_id) : 0);
- row_id = DataBase.readOnly().getMaxID("articles", "rowid");
+ int new_and_unread = db.get_new_unread_count(row_id != null ? int.parse(row_id) : 0);
+ row_id = db.getMaxID("articles", "rowid");
int after = row_id != null ? int.parse(row_id) : 0;
int newArticles = after-before;
if(newArticles > 0)
@@ -266,12 +267,12 @@ public void syncContent(GLib.Cancellable? cancellable = null)
var drop_weeks = drop_articles.to_weeks();
if(drop_weeks != null)
- DataBase.writeAccess().dropOldArticles(-(int)drop_weeks);
+ db.dropOldArticles(-(int)drop_weeks);
var now = new DateTime.now_local();
Settings.state().set_int("last-sync", (int)now.to_unix());
- DataBase.writeAccess().checkpoint();
+ db.checkpoint();
FeedReaderBackend.get_default().newFeedList();
return;
}
@@ -280,6 +281,7 @@ public void InitSyncContent(GLib.Cancellable? cancellable = null)
{
Logger.debug("FeedServer: initial sync");
+ var db = DataBase.writeAccess();
if(syncFeedsAndCategories())
{
var categories = new Gee.LinkedList<Category>();
@@ -297,13 +299,13 @@ public void InitSyncContent(GLib.Cancellable? cancellable = null)
return;
// write categories
- DataBase.writeAccess().write_categories(categories);
+ db.write_categories(categories);
// write feeds
- DataBase.writeAccess().write_feeds(feeds);
+ db.write_feeds(feeds);
// write tags
- DataBase.writeAccess().write_tags(tags);
+ db.write_tags(tags);
FeedReaderBackend.get_default().newFeedList();
}
@@ -323,7 +325,7 @@ public void InitSyncContent(GLib.Cancellable? cancellable = null)
// get articles for each tag
syncProgress(_("Getting tagged articles"));
- foreach(var tag_item in DataBase.readOnly().read_tags())
+ foreach(var tag_item in db.read_tags())
{
getArticles((Settings.general().get_int("max-articles")/8), ArticleStatus.ALL, since, tag_item.getTagID(), true, cancellable);
if(cancellable != null && cancellable.is_cancelled())
@@ -347,7 +349,7 @@ public void InitSyncContent(GLib.Cancellable? cancellable = null)
return;
//update fulltext table
- DataBase.writeAccess().updateFTS();
+ db.updateFTS();
Settings.general().reset("content-grabber");
@@ -361,7 +363,8 @@ private void writeArticles(Gee.List<Article> articles)
{
if(articles.size > 0)
{
- DataBase.writeAccess().update_articles(articles);
+ var db = DataBase.writeAccess();
+ db.update_articles(articles);
// Reverse the list
var new_articles = new Gee.ArrayList<Article>();
@@ -370,7 +373,7 @@ private void writeArticles(Gee.List<Article> articles)
new_articles.insert(0, article);
}
- DataBase.writeAccess().write_articles(new_articles);
+ db.write_articles(new_articles);
FeedReaderBackend.get_default().refreshFeedListCounter();
FeedReaderBackend.get_default().updateArticleList();
}
@@ -383,7 +386,8 @@ public async void grabContent(GLib.Cancellable? cancellable = null)
return;
Logger.debug("FeedServer: grabContent");
- var articles = DataBase.readOnly().readUnfetchedArticles();
+ var db = DataBase.writeAccess();
+ var articles = db.readUnfetchedArticles();
int size = articles.size;
int i = 0;
var new_article_content = new Gee.ArrayList<Article>();
@@ -466,14 +470,14 @@ public async void grabContent(GLib.Cancellable? cancellable = null)
{
if (cancellable != null && cancellable.is_cancelled())
return;
- DataBase.writeAccess().writeContent(content);
+ db.writeContent(content);
}
if (cancellable != null && cancellable.is_cancelled())
return;
//update fulltext table
- DataBase.writeAccess().updateFTS();
+ db.updateFTS();
}
}
diff --git a/src/CachedActionManager.vala b/src/CachedActionManager.vala
index 098e3dae..edfe0c7f 100644
--- a/src/CachedActionManager.vala
+++ b/src/CachedActionManager.vala
@@ -74,19 +74,21 @@ public void markAllRead()
private void addAction(CachedAction action)
{
- if(DataBase.writeAccess().cachedActionNecessary(action))
+ var db = DataBase.writeAccess();
+ if(db.cachedActionNecessary(action))
{
- DataBase.writeAccess().addCachedAction(action.getType(), action.getID());
+ db.addCachedAction(action.getType(), action.getID());
}
else
{
- DataBase.writeAccess().deleteOppositeCachedAction(action);
+ db.deleteOppositeCachedAction(action);
}
}
public void executeActions()
{
- if(DataBase.readOnly().isTableEmpty("CachedActions"))
+ var db = DataBase.writeAccess();
+ if(db.isTableEmpty("CachedActions"))
{
Logger.debug("CachedActionManager - executeActions: no actions to perform");
return;
@@ -95,7 +97,7 @@ public void executeActions()
Logger.debug("CachedActionManager: executeActions");
- var actions = DataBase.writeAccess().readCachedActions();
+ var actions = db.readCachedActions();
foreach(CachedAction action in actions)
{
@@ -141,7 +143,7 @@ public void executeActions()
execute(m_ids.substring(1), m_lastAction);
}
- DataBase.writeAccess().resetCachedActions();
+ db.resetCachedActions();
}
private void execute(string ids, CachedActions action)
diff --git a/src/Utils.vala b/src/Utils.vala
index 3716728d..b463299c 100644
--- a/src/Utils.vala
+++ b/src/Utils.vala
@@ -33,15 +33,16 @@ public static Soup.Session getSession()
public static void generatePreviews(Gee.List<Article> articles)
{
string noPreview = _("No Preview Available");
+ var db = DataBase.readOnly();
foreach(var Article in articles)
{
- if(!DataBase.readOnly().article_exists(Article.getArticleID()))
+ if(!db.article_exists(Article.getArticleID()))
{
if(Article.getPreview() != null && Article.getPreview() != "")
{
continue;
}
- if(!DataBase.readOnly().preview_empty(Article.getArticleID()))
+ if(!db.preview_empty(Article.getArticleID()))
{
continue;
}
@@ -85,9 +86,10 @@ public static void generatePreviews(Gee.List<Article> articles)
public static void checkHTML(Gee.List<Article> articles)
{
+ var db = DataBase.readOnly();
foreach(var Article in articles)
{
- if(!DataBase.readOnly().article_exists(Article.getArticleID()))
+ if(!db.article_exists(Article.getArticleID()))
{
string modified_html = _("No Text available for this article :(");
if(Article.getHTML() != "")
@@ -770,9 +772,10 @@ public static bool onlyShowFeeds()
if(Settings.general().get_boolean("only-feeds"))
return true;
- if(!DataBase.readOnly().haveCategories()
+ var db = DataBase.readOnly();
+ if(!db.haveCategories()
&& !FeedReaderBackend.get_default().supportTags()
- && !DataBase.readOnly().haveFeedsWithoutCat())
+ && !db.haveFeedsWithoutCat())
return true;
return false;
diff --git a/src/Widgets/FeedList.vala b/src/Widgets/FeedList.vala
index 1f9efbf3..bf0cff7e 100644
--- a/src/Widgets/FeedList.vala
+++ b/src/Widgets/FeedList.vala
@@ -465,7 +465,8 @@ private void addTagCategory(int length)
private void createCategories(ref Gee.List<Feed> feeds, bool masterCat, ArticleListState state)
{
- int maxCatLevel = DataBase.readOnly().getMaxCatLevel();
+ var db = DataBase.readOnly();
+ int maxCatLevel = db.getMaxCatLevel();
int length = (int)m_list.get_children().length();
bool supportTags = false;
bool supportCategories = true;
@@ -478,7 +479,7 @@ private void createCategories(ref Gee.List<Feed> feeds, bool masterCat, ArticleL
supportMultiLevelCategories = FeedReaderBackend.get_default().supportMultiLevelCategories();
if((supportTags
- && !DataBase.readOnly().isTableEmpty("tags"))
+ && !db.isTableEmpty("tags"))
|| masterCat)
{
addMasterCategory(length, _("Categories"));
@@ -497,16 +498,16 @@ private void createCategories(ref Gee.List<Feed> feeds, bool masterCat, ArticleL
for(int i = 1; i <= maxCatLevel; i++)
{
- var categories = DataBase.readOnly().read_categories_level(i, feeds);
+ var categories = db.read_categories_level(i, feeds);
- if(DataBase.readOnly().haveFeedsWithoutCat())
+ if(db.haveFeedsWithoutCat())
{
categories.insert(
0,
new Category(
uncategorizedID,
_("Uncategorized"),
- (int)DataBase.readOnly().get_unread_uncategorized(),
+ (int)db.get_unread_uncategorized(),
(int)(categories.size + 10),
CategoryID.MASTER.to_string(),
1
@@ -592,9 +593,10 @@ private void createTags()
public void refreshCounters(ArticleListState state)
{
- uint allCount = (state == ArticleListState.MARKED) ? DataBase.readOnly().get_marked_total() : DataBase.readOnly().get_unread_total();
- var feeds = DataBase.readOnly().read_feeds((state == ArticleListState.MARKED) ? true : false);
- var categories = DataBase.readOnly().read_categories(feeds);
+ var db = DataBase.readOnly();
+ uint allCount = (state == ArticleListState.MARKED) ? db.get_marked_total() : db.get_unread_total();
+ var feeds = db.read_feeds((state == ArticleListState.MARKED) ? true : false);
+ var categories = db.read_categories(feeds);
// double-check
uint feedCount = 0;
@@ -674,7 +676,7 @@ public void refreshCounters(ArticleListState state)
}
}
- if(DataBase.readOnly().haveFeedsWithoutCat())
+ if(db.haveFeedsWithoutCat())
{
foreach(Gtk.Widget row in FeedChildList)
{
@@ -683,12 +685,12 @@ public void refreshCounters(ArticleListState state)
{
if(state == ArticleListState.MARKED)
{
- tmpCatRow.set_unread_count(DataBase.readOnly().get_marked_uncategorized());
+ tmpCatRow.set_unread_count(db.get_marked_uncategorized());
tmpCatRow.activateUnreadEventbox(false);
}
else
{
- tmpCatRow.set_unread_count(DataBase.readOnly().get_unread_uncategorized());
+ tmpCatRow.set_unread_count(db.get_unread_uncategorized());
tmpCatRow.activateUnreadEventbox(true);
}
if(Settings.general().get_boolean("feedlist-only-show-unread") && tmpCatRow.getUnreadCount() != 0)
diff --git a/src/Widgets/MainWindow.vala b/src/Widgets/MainWindow.vala
index e29105ef..76901972 100644
--- a/src/Widgets/MainWindow.vala
+++ b/src/Widgets/MainWindow.vala
@@ -476,14 +476,15 @@ private void markSelectedRead()
{
if(selectedRow[1] == FeedID.ALL.to_string())
{
- var categories = DataBase.readOnly().read_categories();
+ var db = DataBase.readOnly();
+ var categories = db.read_categories();
foreach(Category cat in categories)
{
FeedReaderBackend.get_default().markFeedAsRead(cat.getCatID(), true);
Logger.debug("MainWindow: mark all articles as read cat: %s".printf(cat.getTitle()));
}
- var feeds = DataBase.readOnly().read_feeds_without_cat();
+ var feeds = db.read_feeds_without_cat();
foreach(Feed feed in feeds)
{
FeedReaderBackend.get_default().markFeedAsRead(feed.getFeedID(), false);
diff --git a/src/Widgets/TagPopover.vala b/src/Widgets/TagPopover.vala
index e33ef6db..bbba5981 100644
--- a/src/Widgets/TagPopover.vala
+++ b/src/Widgets/TagPopover.vala
@@ -29,12 +29,13 @@ public TagPopover(Gtk.Widget widget)
m_availableTags = new Gee.ArrayList<Tag>();
m_tags = new Gee.ArrayList<Tag>();
Article? selectedArticle = ColumnView.get_default().getSelectedArticle();
+ var db = DataBase.readOnly();
if(selectedArticle != null)
{
Gee.List<string> tagIDs = selectedArticle.getTagIDs();
foreach(string tagID in tagIDs)
{
- m_tags.add(DataBase.readOnly().read_tag(tagID));
+ m_tags.add(db.read_tag(tagID));
}
}