def add_folder_counts(c):
    """Aggregate subfolder counts from folder_x_folder."""
    sql = """
        SELECT COUNT(*) as count, parent_id
        FROM folder_x_folder
        GROUP BY parent_id
    """
    c.execute(sql)
    data = c.fetchall()
    sql = """
        UPDATE folders
        SET subfolder_count = ?
        WHERE folder_id = ?
    """
    c.executemany(sql, data)
