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

Commit 731e1bd

Browse files
committed
Fix article tagging
A commit a long time ago removed the tags column from articles and replaced it with the taggings table, but it looks like the code to rename and delete tags, and also to show all tagged articles was broken. This fixes all of the references to the old tags column and switches them to reference taggings instead. I also inlined the all-tags subquery. This should fix #840
1 parent 354aa67 commit 731e1bd

File tree

2 files changed

+2
-22
lines changed

2 files changed

+2
-22
lines changed

src/DataBaseReadOnly.vala

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -810,16 +810,9 @@ public Tag? read_tag(string tagID)
810810
row[3].to_int());
811811
}
812812

813-
// FIXME: Inline this as a subquery
814813
protected string getAllTagsCondition()
815814
{
816-
var tags = read_tags();
817-
var conditions = new Gee.ArrayList<string>();
818-
foreach(Tag tag in tags)
819-
{
820-
conditions.add("instr(\"tags\", %s) > 0".printf(SQLite.quote_string(tag.getTagID())));
821-
}
822-
return "(%s)".printf(StringUtils.join(conditions, " OR "));
815+
return "articleID IN (SELECT articleID FROM taggings WHERE instr(tagID, 'global.') = 0)";
823816
}
824817

825818
public Gee.List<Category> read_categories_level(int level, Gee.List<Feed>? feeds = null)

src/DataBaseWriteAccess.vala

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,7 @@ private void delete_article(string articleID, string feedID)
112112
public void dropTag(Tag tag)
113113
{
114114
m_db.execute("DELETE FROM main.tags WHERE tagID = ?", { tag.getTagID() });
115-
116-
var rows = m_db.execute("SELECT tags, articleID FROM main.articles WHERE instr(tags, ?) > 0", { tag.getTagID() });
117-
foreach(var row in rows)
118-
{
119-
string articleID = row[1].to_string();
120-
Gee.List<string> tags = StringUtils.split(row[0].to_string(), ",", true);
121-
if(tags.contains(tag.getTagID()))
122-
tags.remove(tag.getTagID());
123-
124-
m_db.execute("UPDATE main.articles SET tags = ? WHERE articleID = ?",
125-
{ StringUtils.join(tags, ","), articleID });
126-
}
115+
m_db.execute("DELETE FROM main.taggings WHERE tagID = ?", { tag.getTagID() });
127116
}
128117

129118
public void write_feeds(Gee.Collection<Feed> feeds)
@@ -217,8 +206,6 @@ public void update_tag(Tag tag)
217206
{
218207
string newID = tag.getTagID().replace(tag.getTitle(), tag.getTitle());
219208
m_db.execute("UPDATE tags SET tagID = ? WHERE tagID = ?", { newID, tag.getTagID() });
220-
m_db.execute("UPDATE articles SET tags = replace(tags, ?, ?) WHERE instr(tags, ?)",
221-
{ tag.getTagID(), newID, tag.getTagID() });
222209
}
223210
}
224211

0 commit comments

Comments
 (0)