Fix selections that include task with no tags

gtask_related_email
Alex Baker 4 years ago
parent 274d98160a
commit c8e313c67a

@ -6,7 +6,6 @@ import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.tasks.makers.TagDataMaker.NAME;
import static org.tasks.makers.TagDataMaker.UID;
import static org.tasks.makers.TagDataMaker.newTagData;
import static org.tasks.makers.TagMaker.TAGDATA;
import static org.tasks.makers.TagMaker.TAGUID;
@ -105,7 +104,6 @@ public class TagDataDaoTest extends InjectingTestCase {
newTag(1, "tag1", "tag2");
newTag(2, "tag2", "tag3");
assertEquals(
newHashSet("tag1", "tag3"), tagDataDao.getTagSelections(ImmutableList.of(1L, 2L)).first);
}
@ -123,8 +121,7 @@ public class TagDataDaoTest extends InjectingTestCase {
newTag(1, "tag1", "tag2");
newTag(2, "tag2", "tag3");
assertEquals(
newHashSet("tag2"), tagDataDao.getTagSelections(ImmutableList.of(1L, 2L)).second);
assertEquals(newHashSet("tag2"), tagDataDao.getTagSelections(ImmutableList.of(1L, 2L)).second);
}
@Test
@ -135,6 +132,26 @@ public class TagDataDaoTest extends InjectingTestCase {
assertTrue(tagDataDao.getTagSelections(ImmutableList.of(1L, 2L)).second.isEmpty());
}
@Test
public void getSelectionsWithNoTags() {
newTag(1);
Pair<Set<String>, Set<String>> selections = tagDataDao.getTagSelections(ImmutableList.of(1L));
assertTrue(selections.first.isEmpty());
assertTrue(selections.second.isEmpty());
}
@Test
public void noCommonSelectionsWhenOneTaskHasNoTags() {
newTag(1, "tag1");
newTag(2);
Pair<Set<String>, Set<String>> selections =
tagDataDao.getTagSelections(ImmutableList.of(1L, 2L));
assertEquals(newHashSet("tag1"), selections.first);
assertTrue(selections.second.isEmpty());
}
private void newTag(long taskId, String... tags) {
Task task = newTask(with(ID, taskId));
taskDao.createNew(task);

@ -5,6 +5,7 @@ import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Sets.difference;
import static com.google.common.collect.Sets.newHashSet;
import static java.util.Collections.emptySet;
import static org.tasks.db.DbUtils.MAX_SQLITE_ARGS;
import static org.tasks.db.DbUtils.batch;
@ -76,11 +77,12 @@ public abstract class TagDataDao {
public Pair<Set<String>, Set<String>> getTagSelections(List<Long> tasks) {
List<String> allTags = getAllTags(tasks);
Collection<Set<String>> tags = Collections2.transform(allTags, t -> newHashSet(t.split(",")));
Collection<Set<String>> tags =
Collections2.transform(allTags, t -> t == null ? emptySet() : newHashSet(t.split(",")));
Set<String> partialTags = newHashSet(concat(tags));
Set<String> commonTags = null;
if (tags.isEmpty()) {
commonTags = Collections.emptySet();
commonTags = emptySet();
} else {
for (Set<String> s : tags) {
if (commonTags == null) {
@ -95,8 +97,8 @@ public abstract class TagDataDao {
}
@Query(
"SELECT IFNULL(GROUP_CONCAT(DISTINCT(tag_uid)), '') FROM tasks"
+ " INNER JOIN tags ON tags.task = tasks._id"
"SELECT GROUP_CONCAT(DISTINCT(tag_uid)) FROM tasks"
+ " LEFT JOIN tags ON tags.task = tasks._id"
+ " WHERE tasks._id IN (:tasks)"
+ " GROUP BY tasks._id")
abstract List<String> getAllTags(List<Long> tasks);

Loading…
Cancel
Save