~sircmpwn/todo.sr.ht#255: 
Missing comment count in overview after ticket import

I imported a number of tickets exported from a flyspray(.org) tracker and while successful, the overview doesn't show the number of comments per ticket.

The affected todo tracker is ~aparcar/openwrt-bugs-import-test-2. The very first ticket show no (0) comments in the overview while there is actually one.

Status
REPORTED
Submitter
~aparcar
Assigned to
No-one
Submitted
1 year, 4 months ago
Updated
1 year, 4 months ago
Labels
No labels applied.

~aparcar 1 year, 4 months ago

Problem is ticket comments are stored as an integer and the import doesn't set that value automatically. Looking at the migration code it looks like after every import something like this should run:

UPDATE ticket t
        SET comment_count = (
            SELECT count(*)
            FROM ticket_comment
            WHERE ticket_id = t.id AND superceeded_by_id IS NULL
        )

~aparcar 1 year, 4 months ago

Correction, something like the following could do a better job. I'll setup a test instance and report back:

diff --git a/todosrht/tracker_import.py b/todosrht/tracker_import.py
index fd89311..e68a59f 100644
--- a/todosrht/tracker_import.py
+++ b/todosrht/tracker_import.py
@@ -70,6 +70,7 @@ def _import_comment(ticket, event, edata):
             comment.authenticity = TicketAuthenticity.authentic
         else:
             comment.authenticity = TicketAuthenticity.tampered
+    ticket.comment_count += 1
     db.session.add(comment)
     db.session.flush()
     event.comment_id = comment.id
Register here or Log in to comment, or comment via email.