Your answer is in get_comment_tree() in /app/misc.py
comments = SubPostComment.select(SubPostComment.cid, SubPostComment.parentcid).where(SubPostComment.pid == post['pid']).order_by(SubPostComment.score.desc()).dicts()
Here it is retrieving all comments cid, parentcid and it is passed as arguments parameter in get_comment_tree()
(post is archived)