Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 9194a3b

Browse files
committed
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.
1 parent 89ddf05 commit 9194a3b

23 files changed

+165
-115
lines changed

plugins/backend/bazqux/bazquxAPI.vala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public bool getCategoriesAndTags(Gee.List<Feed> feeds, Gee.List<Category> catego
162162
uint length = array.get_length();
163163
int orderID = 0;
164164

165+
var db = DataBase.readOnly();
165166
for (uint i = 0; i < length; i++)
166167
{
167168
Json.Object object = array.get_object_element(i);
@@ -191,7 +192,7 @@ public bool getCategoriesAndTags(Gee.List<Feed> feeds, Gee.List<Category> catego
191192
new Tag(
192193
id,
193194
title,
194-
DataBase.readOnly().getTagColor()
195+
db.getTagColor()
195196
)
196197
);
197198
}
@@ -323,6 +324,7 @@ public string? getArticles(Gee.List<Article> articles, int count, ArticleStatus
323324
var array = root.get_array_member("items");
324325
uint length = array.get_length();
325326

327+
var db = DataBase.readOnly();
326328
for (uint i = 0; i < length; i++)
327329
{
328330
Json.Object object = array.get_object_element(i);
@@ -341,7 +343,7 @@ public string? getArticles(Gee.List<Article> articles, int count, ArticleStatus
341343
marked = true;
342344
else if(cat.has_suffix("com.google/read"))
343345
read = true;
344-
else if(cat.contains("/label/") && DataBase.readOnly().getTagName(cat) != null)
346+
else if(cat.contains("/label/") && db.getTagName(cat) != null)
345347
tags.add(cat);
346348
}
347349

plugins/backend/bazqux/bazquxInterface.vala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,14 @@ public void setCategoryRead(string catID)
257257

258258
public void markAllItemsRead()
259259
{
260-
var categories = DataBase.readOnly().read_categories();
260+
var db = DataBase.readOnly();
261+
var categories = db.read_categories();
261262
foreach(Category cat in categories)
262263
{
263264
m_api.markAsRead(cat.getCatID());
264265
}
265266

266-
var feeds = DataBase.readOnly().read_feeds_without_cat();
267+
var feeds = db.read_feeds_without_cat();
267268
foreach(Feed feed in feeds)
268269
{
269270
m_api.markAsRead(feed.getFeedID());

plugins/backend/decsync/decsyncInterface.vala

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,10 @@ public void setArticleIsRead(string articleIDs, ArticleStatus readStatus)
302302
var read = readStatus == ArticleStatus.READ;
303303
Logger.debug("Mark " + articleIDs + " as " + (read ? "read" : "unread"));
304304
var entries = new Gee.ArrayList<Decsync.EntryWithPath>();
305+
var db = DataBase.readOnly();
305306
foreach (var articleID in articleIDs.split(","))
306307
{
307-
Article? article = DataBase.readOnly().read_article(articleID);
308+
Article? article = db.read_article(articleID);
308309
if (article != null)
309310
{
310311
var path = articleToPath(article, "read");
@@ -380,12 +381,13 @@ public bool addFeed(string feedURL, string? catID, string? newCatName, out strin
380381

381382
public bool addFeedWithDecsync(string feedURL, string? catID, string? newCatName, out string feedID, out string errmsg, bool updateDecsync = true)
382383
{
384+
var db = DataBase.writeAccess();
383385
var catIDs = new Gee.ArrayList<string>();
384386
if(catID == null && newCatName != null)
385387
{
386388
string cID = createCategory(newCatName, null);
387389
var cat = new Category(cID, newCatName, 0, 99, CategoryID.MASTER.to_string(), 1);
388-
DataBase.writeAccess().write_categories(ListUtils.single(cat));
390+
db.write_categories(ListUtils.single(cat));
389391
catIDs.add(cID);
390392
}
391393
else if(catID != null && newCatName == null)
@@ -404,8 +406,8 @@ public bool addFeedWithDecsync(string feedURL, string? catID, string? newCatName
404406

405407
if(feed != null)
406408
{
407-
if(!DataBase.readOnly().feed_exists(feed.getURL())) {
408-
DataBase.writeAccess().write_feeds(ListUtils.single(feed));
409+
if(!db.feed_exists(feed.getURL())) {
410+
db.write_feeds(ListUtils.single(feed));
409411

410412
if (updateDecsync)
411413
{
@@ -455,8 +457,9 @@ public void moveFeed(string feedID, string newCatID, string? currentCatID)
455457

456458
public string createCategory(string title, string? parentID)
457459
{
458-
string? catID = DataBase.readOnly().getCategoryID(title);
459-
while (catID == null || DataBase.readOnly().read_category(catID) != null)
460+
var db = DataBase.readOnly();
461+
string? catID = db.getCategoryID(title);
462+
while (catID == null || db.read_category(catID) != null)
460463
{
461464
catID = "catID%05d".printf(Random.int_range(0, 100000));
462465
}
@@ -561,6 +564,7 @@ public void getArticles(int count, ArticleStatus whatToGet, DateTime? since, str
561564

562565
Logger.debug("Got %u articles".printf(doc.get_items().length()));
563566
var newArticles = new Gee.ArrayList<Article>();
567+
var db = DataBase.readOnly();
564568
foreach(Rss.Item item in doc.get_items())
565569
{
566570
string? articleID = item.guid;
@@ -576,9 +580,9 @@ public void getArticles(int count, ArticleStatus whatToGet, DateTime? since, str
576580
articleID = item.link;
577581
}
578582

579-
if (DataBase.readOnly().read_article(articleID) != null)
580-
{
581-
continue;
583+
if (db.read_article(articleID) != null)
584+
{
585+
continue;
582586
}
583587

584588
var date = Rfc822.parseDate(item.pub_date);

plugins/backend/decsync/decsyncListeners.vala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public override void onSubdirEntryUpdate(Gee.List<string> path, Decsync.Entry en
5050
{
5151
Logger.debug((added ? "mark " : "unmark ") + articleID);
5252
}
53-
Article? article = DataBase.readOnly().read_article(articleID);
53+
var db = DataBase.writeAccess();
54+
Article? article = db.read_article(articleID);
5455
if (article == null)
5556
{
5657
Logger.info("Unkown article " + articleID);
@@ -64,7 +65,7 @@ public override void onSubdirEntryUpdate(Gee.List<string> path, Decsync.Entry en
6465
{
6566
article.setMarked(added ? ArticleStatus.MARKED : ArticleStatus.UNMARKED);
6667
}
67-
DataBase.writeAccess().update_article(article);
68+
db.update_article(article);
6869
}
6970
}
7071

@@ -163,7 +164,8 @@ public override void onSubfileEntryUpdate(Decsync.Entry entry, Unit extra)
163164
Logger.warning("Invalid feedID " + Json.to_string(entry.key, false));
164165
return;
165166
}
166-
var feed = DataBase.readOnly().read_feed(feedID);
167+
var db = DataBase.writeAccess();
168+
var feed = db.read_feed(feedID);
167169
if (feed == null) return;
168170
var currentCatID = feed.getCatString();
169171
string newCatID;
@@ -181,7 +183,7 @@ public override void onSubfileEntryUpdate(Decsync.Entry entry, Unit extra)
181183
return;
182184
}
183185
addCategory(m_plugin, newCatID);
184-
DataBase.writeAccess().move_feed(feedID, currentCatID, newCatID);
186+
db.move_feed(feedID, currentCatID, newCatID);
185187
}
186188
}
187189

plugins/backend/feedbin/feedbinInterface.vala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,10 @@ private void setRead(string id, FeedListType type)
285285
{
286286
const int count = 1000;
287287
int num_articles = 1; // set to any value > 0
288+
var db = DataBase.readOnly();
288289
for(var offset = 0; num_articles > 0; offset += count)
289290
{
290-
var articles = DataBase.readOnly().read_articles(id, type, ArticleListState.ALL, "", count, offset);
291+
var articles = db.read_articles(id, type, ArticleListState.ALL, "", count, offset);
291292
var entry_ids = new Gee.ArrayList<int64?>();
292293
foreach(var article in articles)
293294
{
@@ -643,6 +644,7 @@ requires (count >= 0)
643644
{
644645
try
645646
{
647+
var db = DataBase.readOnly();
646648
int64? feed_id = null;
647649
if(!is_tag_id && feed_id_str != null)
648650
feed_id = int64.parse(feed_id_str);
@@ -683,7 +685,7 @@ requires (count >= 0)
683685
for(var offset = 0, c = 1000; ; offset += c)
684686
{
685687
var articles = new Gee.ArrayList<Article>();
686-
var existing_articles = DataBase.readOnly().read_articles(search_feed_id, search_type, ArticleListState.ALL, "", c, offset);
688+
var existing_articles = db.read_articles(search_feed_id, search_type, ArticleListState.ALL, "", c, offset);
687689
if(existing_articles.size == 0)
688690
break;
689691

plugins/backend/feedhq/feedhqInterface.vala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,14 @@ public void setCategoryRead(string catID)
259259

260260
public void markAllItemsRead()
261261
{
262-
var categories = DataBase.readOnly().read_categories();
262+
var db = DataBase.readOnly();
263+
var categories = db.read_categories();
263264
foreach(Category cat in categories)
264265
{
265266
m_api.markAsRead(cat.getCatID());
266267
}
267268

268-
var feeds = DataBase.readOnly().read_feeds_without_cat();
269+
var feeds = db.read_feeds_without_cat();
269270
foreach(Feed feed in feeds)
270271
{
271272
m_api.markAsRead(feed.getFeedID());

plugins/backend/feedly/feedlyAPI.vala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,15 @@ public bool getTags(Gee.List<Tag> tags)
271271
Json.Array array = parser.get_root().get_array ();
272272
uint length = array.get_length();
273273

274+
var db = DataBase.readOnly();
274275
for (uint i = 0; i < length; i++) {
275276
Json.Object object = array.get_object_element(i);
276277

277278
tags.add(
278279
new Tag(
279280
object.get_string_member("id"),
280281
object.has_member("label") ? object.get_string_member("label") : "",
281-
DataBase.readOnly().getTagColor()
282+
db.getTagColor()
282283
)
283284
);
284285
}
@@ -595,9 +596,10 @@ public bool addSubscription(string feedURL, string? title = null, string? catIDs
595596
var catArray = catIDs.split(",");
596597
Json.Array cats = new Json.Array();
597598

599+
var db = DataBase.readOnly();
598600
foreach(string catID in catArray)
599601
{
600-
string catName = DataBase.readOnly().getCategoryName(catID);
602+
string catName = db.getCategoryName(catID);
601603
Json.Object catObject = new Json.Object();
602604
catObject.set_string_member("id", catID);
603605
catObject.set_string_member("label", catName);
@@ -617,7 +619,8 @@ public bool addSubscription(string feedURL, string? title = null, string? catIDs
617619

618620
public void moveSubscription(string feedID, string newCatID, string? oldCatID = null)
619621
{
620-
var Feed = DataBase.readOnly().read_feed(feedID);
622+
var db = DataBase.readOnly();
623+
var Feed = db.read_feed(feedID);
621624

622625
Json.Object object = new Json.Object();
623626
object.set_string_member("id", feedID);
@@ -631,15 +634,15 @@ public void moveSubscription(string feedID, string newCatID, string? oldCatID =
631634
{
632635
if(catID != oldCatID)
633636
{
634-
string catName = DataBase.readOnly().getCategoryName(catID);
637+
string catName = db.getCategoryName(catID);
635638
Json.Object catObject = new Json.Object();
636639
catObject.set_string_member("id", catID);
637640
catObject.set_string_member("label", catName);
638641
cats.add_object_element(catObject);
639642
}
640643
}
641644

642-
string newCatName = DataBase.readOnly().getCategoryName(newCatID);
645+
string newCatName = db.getCategoryName(newCatID);
643646
Json.Object catObject = new Json.Object();
644647
catObject.set_string_member("id", newCatID);
645648
catObject.set_string_member("label", newCatName);

plugins/backend/feedly/feedlyInterface.vala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,9 @@ public void markAllItemsRead()
218218
string catArray = "";
219219
string feedArray = "";
220220

221-
var categories = DataBase.readOnly().read_categories();
222-
var feeds = DataBase.readOnly().read_feeds_without_cat();
221+
var db = DataBase.readOnly();
222+
var categories = db.read_categories();
223+
var feeds = db.read_feeds_without_cat();
223224

224225
foreach(Category cat in categories)
225226
{

plugins/backend/inoreader/InoReaderAPI.vala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public bool getCategoriesAndTags(Gee.List<Feed> feeds, Gee.List<Category> catego
162162
uint length = array.get_length();
163163
int orderID = 0;
164164

165+
var db = DataBase.readOnly();
165166
for (uint i = 0; i < length; i++)
166167
{
167168
Json.Object object = array.get_object_element(i);
@@ -190,7 +191,7 @@ public bool getCategoriesAndTags(Gee.List<Feed> feeds, Gee.List<Category> catego
190191
new Tag(
191192
id,
192193
title,
193-
DataBase.readOnly().getTagColor()
194+
db.getTagColor()
194195
)
195196
);
196197
}
@@ -318,6 +319,7 @@ public string? getArticles(Gee.List<Article> articles, int count, ArticleStatus
318319
var array = root.get_array_member("items");
319320
uint length = array.get_length();
320321

322+
var db = DataBase.readOnly();
321323
for (uint i = 0; i < length; i++)
322324
{
323325
Json.Object object = array.get_object_element(i);
@@ -336,7 +338,7 @@ public string? getArticles(Gee.List<Article> articles, int count, ArticleStatus
336338
marked = true;
337339
else if(cat.has_suffix("com.google/read"))
338340
read = true;
339-
else if(cat.contains("/label/") && DataBase.readOnly().getTagName(cat) != null)
341+
else if(cat.contains("/label/") && db.getTagName(cat) != null)
340342
tags.add(cat);
341343
}
342344

plugins/backend/inoreader/InoReaderInterface.vala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,14 @@ public void setCategoryRead(string catID)
232232

233233
public void markAllItemsRead()
234234
{
235-
var categories = DataBase.readOnly().read_categories();
235+
var db = DataBase.readOnly();
236+
var categories = db.read_categories();
236237
foreach(Category cat in categories)
237238
{
238239
m_api.markAsRead(cat.getCatID());
239240
}
240241

241-
var feeds = DataBase.readOnly().read_feeds_without_cat();
242+
var feeds = db.read_feeds_without_cat();
242243
foreach(Feed feed in feeds)
243244
{
244245
m_api.markAsRead(feed.getFeedID());

0 commit comments

Comments
 (0)