읽지 않은 메시지 수가 '읽지 않은 메시지(14)'로 표시되지만 /unread가 비어 있습니다

좋아요, 이 rails 스크립트는 전역적인 “모두 읽음으로 표시” 기능을 수행하여 모든 사용자unread 카운트를 0으로 강제 재설정합니다. 따라서 유령 상태의 읽지 않음 항목뿐만 아니라 합법적인 읽지 않음 카운트도 함께 초기화됩니다. rails에서 sql 명령어로 이를 수행할 수 있습니다. 다만 근본적인 버그를 수정하는 것은 아닙니다. 또한 최근 백업이 있다면 좋은 방법이지만, 제 개발 포럼에서 테스트해보니 잘 작동했습니다.

cd /var/discourse
./launcher enter app
rails c

아래 전체 블록을 붙여넣고 엔터를 누르세요

sql = <<~SQL
  UPDATE topic_users
  SET last_read_post_number = topics.highest_post_number
  FROM topics
  WHERE topics.id = topic_users.topic_id
    AND COALESCE(topic_users.last_read_post_number, 0) < topics.highest_post_number
    AND topic_users.notification_level IN (2, 3, 4) -- Tracking, Watching, Watching First Post
SQL

# 업데이트 실행
result = ActiveRecord::Base.connection.execute(sql)
puts "Successfully cleared #{result.cmd_tuples} unread topics site-wide."

# 클라이언트 브라우저가 캐시된 상태를 폐기하고 데이터베이스와 동기화하도록 강제
MessageBus.publish("/topic-tracking-state", { clear: true })

사용자들은 초기화된 unread 상태를 확인하려면 강제 새로고침을 해야 할 수 있습니다.

4개의 좋아요