266
262
return shortlist([row[0] for row in cur.fetchall()])
269
def get_bug_tags_open_count(context_condition, user, wanted_tags=None):
270
"""Return all the used bug tags with their open bug count.
265
def get_bug_tags_open_count(context_condition, user, tag_limit=0,
267
"""Worker for IBugTarget.getUsedBugTagsWithOpenCounts.
269
See `IBugTarget` for details.
271
The only change is that this function takes a SQL expression for limiting
272
273
:param context_condition: A Storm SQL expression, limiting the
273
274
used tags to a specific context. Only the BugTask table may be
274
275
used to choose the context.
275
:param user: The user performing the search.
276
:param wanted_tags: A set of tags within which to restrict the search.
278
:return: A list of tuples, (tag name, open bug count).
282
Join(BugTask, BugTask.bugID == BugTag.bugID),
278
from lp.bugs.model.bugsummary import BugSummary
281
tags = dict((tag, 0) for tag in include_tags)
282
store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR)
283
admin_team = getUtility(ILaunchpadCelebrities).admin
284
if user is not None and not user.inTeam(admin_team):
285
store = store.with_(SQL(
287
"SELECT team from TeamParticipation WHERE person=?)", (user.id,)))
284
288
where_conditions = [
285
BugTask.status.is_in(UNRESOLVED_BUGTASK_STATUSES),
289
BugSummary.status.is_in(UNRESOLVED_BUGTASK_STATUSES),
290
BugSummary.tag != None,
286
291
context_condition,
288
if wanted_tags is not None:
289
where_conditions.append(BugTag.tag.is_in(wanted_tags))
290
privacy_filter = get_bug_privacy_filter(user)
292
# The EXISTS sub-select avoids a join against Bug, improving
293
# performance significantly.
294
where_conditions.append(BugSummary.viewed_by_id == None)
295
elif not user.inTeam(admin_team):
294
296
where_conditions.append(
296
columns=[True], tables=[Bug],
297
where=And(Bug.id == BugTag.bugID, SQLRaw(privacy_filter)))))
298
store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR)
299
return store.using(*tables).find(
300
tag_count_columns, *where_conditions).group_by(BugTag.tag).order_by(
301
Desc(Count()), BugTag.tag)
298
BugSummary.viewed_by_id == None,
299
BugSummary.viewed_by_id.is_in(SQL("SELECT team FROM teams"))
301
tag_count_columns = (BugSummary.tag, Sum(BugSummary.count))
302
# Always query for used
304
return store.find(tag_count_columns, *(where_conditions + list(args))
305
).group_by(BugSummary.tag).order_by(
306
Desc(Sum(BugSummary.count)), BugSummary.tag)
309
used = used[:tag_limit]
311
# Union in a query for just include_tags.
312
used = used.union(_query(BugSummary.tag.is_in(include_tags)))
313
tags.update(dict(used))
304
317
class BugBecameQuestionEvent: