ダッシュボードの新規投稿統計が壊れています

root@prometheus-discourse-sidemount:/var/www/discourse# rails c
Plugin name is 'discourse-docs', but plugin directory is named 'discourse-knowledge-explorer'
Plugin name is 'discourse-user-notes', but plugin directory is named 'discourse-staff-notes'
Loading production environment (Rails 7.2.2.1)
discourse(prod)> Post.public_posts_count_per_day(4.weeks.ago, Time.zone.now)
=> {}
discourse(prod)>

Lots… :wink: Taken from the container config yaml:

https://github.com/discourse/docker_manager.git
https://github.com/discourse/discourse-adplugin.git
https://github.com/discourse/discourse-affiliate.git
https://github.com/discourse/discourse-ai.git
https://github.com/discourse/discourse-akismet.git
https://github.com/pfaffman/discourse-allow-pm-to-staff.git
https://github.com/discourse/discourse-animated-avatars.git
https://github.com/discourse/discourse-apple-auth.git
https://github.com/discourse/discourse-assign.git
https://github.com/discourse/discourse-authentication-validations.git
https://github.com/discourse/discourse-auto-deactivate.git
https://github.com/discourse/discourse-bbcode.git
https://github.com/discourse/discourse-bcc.git
https://github.com/discourse/discourse-cakeday.git
https://github.com/discourse/discourse-calendar.git
https://github.com/discourse/discourse-characters-required.git
https://github.com/discourse/discourse-chat-integration.git
https://github.com/discourse/discourse-data-explorer.git
https://github.com/discourse/discourse-fingerprint.git
https://github.com/discourse/discourse-follow.git
https://github.com/leodavidson/discourse-forcemoderation.git
https://github.com/discourse/discourse-gamification.git
https://github.com/discourse/discourse-hcaptcha.git
https://github.com/discourse/discourse-knowledge-explorer.git
https://github.com/angusmcleod/discourse-locations.git
https://github.com/discourse/discourse-login-with-amazon.git
https://github.com/discourse/discourse-math.git
https://github.com/discourse/discourse-microsoft-auth.git
https://github.com/discoursehosting/discourse-migratepassword.git
https://github.com/discourse/discourse-policy.git
https://github.com/paviliondev/discourse-post-badges-plugin.git
https://github.com/discourse/discourse-post-voting.git
https://github.com/communiteq/discourse-private-topics.git
https://github.com/discourse/discourse-push-notifications.git
https://github.com/featheredtoast/discourse-pushover-notifications.git
https://github.com/paviliondev/discourse-ratings.git
https://github.com/discourse/discourse-reactions.git
https://github.com/discourse/discourse-restricted-replies.git
https://github.com/discourse/discourse-saved-searches.git
https://github.com/discourse/discourse-shared-edits.git
https://github.com/discourse/discourse-signatures.git
https://github.com/discourse/discourse-solved.git
https://github.com/discourse/discourse-staff-alias.git
https://github.com/discourse/discourse-staff-notes.git
https://github.com/discourse/discourse-steam-login.git
https://github.com/singerscreations/discourse-stopforumspam.git
https://github.com/discourse/discourse-styleguide.git
https://github.com/discourse/discourse-subscriptions.git
https://github.com/davidtaylorhq/discourse-telegram-notifications.git
https://github.com/discourse/discourse-templates.git
https://github.com/discourse/discourse-tooltips.git
https://github.com/jannolii/discourse-topic-trade-buttons.git
https://github.com/discourse/discourse-topic-voting.git
https://github.com/discourse/discourse-translator.git
https://github.com/discourse/discourse-user-field-prompt.git
https://github.com/discourse/discourse-whos-online.git
https://github.com/discourse/discourse-yearly-review.git

Btw, as @qingfeng1024 is experiencing this problem as well, it does not seem to be a personal problem here. Maybe he can tell us also what the tests above show on/in the forum there and also what plugins are used?

「いいね!」 2

@martin この問題について何かアイデアはありますか?

「いいね!」 1

すみません、少し見落としていました。

@qingfeng1024 Railsコンソールでこれを実行した場合、あなたも全く同じことが起こりますか?

MethodProfiler.output_sql_to_stderr!
Report.find("posts", start_date: 4.weeks.ago, end_date: Time.zone.now).data

この投稿のような出力が表示されるはずですが、ここにコピー&ペーストしていただけますか? Dashboard New Posts statistics broken - #18 by Roi

@kris.kotlarek ここでは何も解決していません。このトピックから何か目立つことはありますか?

「いいね!」 2
root@shannon-20250121-app:/var/www/discourse# rails c
Plugin name is 'DiscourseMatheditor', but plugin directory is named 'discourse-matheditor'
Loading production environment (Rails 7.2.2.1)



discourse(prod)> MethodProfiler.output_sql_to_stderr!
Stop! This instrumentation is not intended for use in production outside of debugging scenarios. Please be sure you know what you are doing when enabling this instrumentation.
=> true




discourse(prod)> Report.find("posts", start_date: 4.weeks.ago, end_date: Time.zone.now).data
debugsql (sql): SET client_min_messages TO 'warning'
debugsql (sec): 0.0
debugsql (sql): SET standard_conforming_strings = on
debugsql (sec): 0.0
debugsql (sql): SET intervalstyle = iso_8601
debugsql (sec): 0.0
debugsql (sql): SELECT t.oid, t.typname
FROM pg_type as t
WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'numeric', 'bool', 'timestamp', 'timestamptz', 'date')
debugsql (sec): 0.001
debugsql (sql): SET SESSION timezone TO 'UTC'
debugsql (sec): 0.0
debugsql (sql): SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
FROM pg_type as t
LEFT JOIN pg_range as r ON oid = rngtypid
WHERE
  t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'text', 'varchar', 'char', 'name', 'bpchar', 'bool', 'bit', 'varbit', 'date', 'money', 'bytea', 'point', 'hstore', 'json', 'jsonb', 'cidr', 'inet', 'uuid', 'xml', 'tsvector', 'macaddr', 'citext', 'ltree', 'line', 'lseg', 'box', 'path', 'polygon', 'circle', 'numeric', 'interval', 'time', 'timestamp', 'timestamptz')
debugsql (sec): 0.002
debugsql (sql): SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
FROM pg_type as t
LEFT JOIN pg_range as r ON oid = rngtypid
WHERE
  t.typtype IN ('r', 'e', 'd')
debugsql (sec): 0.001
debugsql (sql): SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
FROM pg_type as t
LEFT JOIN pg_range as r ON oid = rngtypid
WHERE
  t.typelem IN (16, 17, 18, 19, 20, 21, 23, 25, 26, 114, 142, 600, 601, 602, 603, 604, 628, 700, 701, 718, 790, 829, 869, 650, 1042, 1043, 1082, 1083, 1114, 1184, 1186, 1560, 1562, 1700, 2950, 3614, 3802, 16924, 88307, 88314, 106343, 106350, 13223, 13226, 13228, 13234, 13236, 3904, 3906, 3908, 3910, 3912, 3926)
debugsql (sec): 0.001
debugsql (sql): SELECT a.attname, format_type(a.atttypid, a.atttypmod),
       pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
       c.collname, col_description(a.attrelid, a.attnum) AS comment,
       attidentity AS identity,
       attgenerated as attgenerated
  FROM pg_attribute a
  LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
  LEFT JOIN pg_type t ON a.atttypid = t.oid
  LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
 WHERE a.attrelid = '"themes"'::regclass
   AND a.attnum > 0 AND NOT a.attisdropped
 ORDER BY a.attnum
debugsql (sec): 0.002
debugsql (sql): SHOW max_identifier_length
debugsql (sec): 0.0
debugsql (sql): ;
debugsql (sec): 0.0
debugsql (sql): SELECT a.attname
  FROM (
         SELECT indrelid, indkey, generate_subscripts(indkey, 1) idx
           FROM pg_index
          WHERE indrelid = '"themes"'::regclass
            AND indisprimary
       ) i
  JOIN pg_attribute a
    ON a.attrelid = i.indrelid
   AND a.attnum = i.indkey[i.idx]
 ORDER BY i.idx
debugsql (sec): 0.008
debugsql (sql): SELECT "themes".* FROM "themes" WHERE "themes"."id" = 2 ORDER BY "themes"."id" ASC LIMIT 1
debugsql (sec): 0.0
debugsql (sql): ;
debugsql (sec): 0.0
debugsql (sql): SELECT a.attname
  FROM (
         SELECT indrelid, indkey, generate_subscripts(indkey, 1) idx
           FROM pg_index
          WHERE indrelid = '"color_schemes"'::regclass
            AND indisprimary
       ) i
  JOIN pg_attribute a
    ON a.attrelid = i.indrelid
   AND a.attnum = i.indkey[i.idx]
 ORDER BY i.idx
debugsql (sec): 0.008
debugsql (sql): ;
debugsql (sec): 0.0
debugsql (sql): SELECT a.attname, format_type(a.atttypid, a.atttypmod),
       pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
       c.collname, col_description(a.attrelid, a.attnum) AS comment,
       attidentity AS identity,
       attgenerated as attgenerated
  FROM pg_attribute a
  LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
  LEFT JOIN pg_type t ON a.atttypid = t.oid
  LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
 WHERE a.attrelid = '"color_schemes"'::regclass
   AND a.attnum > 0 AND NOT a.attisdropped
 ORDER BY a.attnum
debugsql (sec): 0.001
debugsql (sql): ;
debugsql (sec): 0.0
debugsql (sql): SELECT "color_schemes".* FROM "color_schemes" WHERE (color_schemes.id NOT IN (SELECT color_scheme_id FROM theme_color_schemes)) AND "color_schemes"."id" = 5 LIMIT 1
debugsql (sec): 0.001
debugsql (sql): ;
debugsql (sec): 0.0
debugsql (sql): SELECT a.attname
  FROM (
         SELECT indrelid, indkey, generate_subscripts(indkey, 1) idx
           FROM pg_index
          WHERE indrelid = '"color_scheme_colors"'::regclass
            AND indisprimary
       ) i
  JOIN pg_attribute a
    ON a.attrelid = i.indrelid
   AND a.attnum = i.indkey[i.idx]
 ORDER BY i.idx
debugsql (sec): 0.008
debugsql (sql): ;
debugsql (sec): 0.0
debugsql (sql): SELECT a.attname, format_type(a.atttypid, a.atttypmod),
       pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
       c.collname, col_description(a.attrelid, a.attnum) AS comment,
       attidentity AS identity,
       attgenerated as attgenerated
  FROM pg_attribute a
  LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
  LEFT JOIN pg_type t ON a.atttypid = t.oid
  LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
 WHERE a.attrelid = '"color_scheme_colors"'::regclass
   AND a.attnum > 0 AND NOT a.attisdropped
 ORDER BY a.attnum
debugsql (sec): 0.001
debugsql (sql): ;
debugsql (sec): 0.0
debugsql (sql): SELECT "color_scheme_colors".* FROM "color_scheme_colors" WHERE "color_scheme_colors"."color_scheme_id" = 5 ORDER BY id ASC
debugsql (sec): 0.001
debugsql (sql): BEGIN
debugsql (sec): 0.0
debugsql (sql): SET TRANSACTION READ ONLY
debugsql (sec): 0.002
debugsql (sql): SET LOCAL statement_timeout = 20000
debugsql (sec): 0.0
debugsql (sql): SELECT a.attname, format_type(a.atttypid, a.atttypmod),
       pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
       c.collname, col_description(a.attrelid, a.attnum) AS comment,
       attidentity AS identity,
       attgenerated as attgenerated
  FROM pg_attribute a
  LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
  LEFT JOIN pg_type t ON a.atttypid = t.oid
  LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
 WHERE a.attrelid = '"posts"'::regclass
   AND a.attnum > 0 AND NOT a.attisdropped
 ORDER BY a.attnum
debugsql (sql): SET client_min_messages TO 'warning'
debugsql (sec): 0.0
debugsql (sql): SET standard_conforming_strings = on
debugsql (sec): 0.0
debugsql (sql): SET intervalstyle = iso_8601
debugsql (sec): 0.0
debugsql (sql): SELECT t.oid, t.typname
FROM pg_type as t
WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'numeric', 'bool', 'timestamp', 'timestamptz', 'date')
debugsql (sec): 0.003
debugsql (sql): SELECT a.attname, format_type(a.atttypid, a.atttypmod),
       pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
       c.collname, col_description(a.attrelid, a.attnum) AS comment,
       attidentity AS identity,
       attgenerated as attgenerated
  FROM pg_attribute a
  LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
  LEFT JOIN pg_type t ON a.atttypid = t.oid
  LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
 WHERE a.attrelid = '"category_custom_fields"'::regclass
   AND a.attnum > 0 AND NOT a.attisdropped
 ORDER BY a.attnum
debugsql (sec): 0.005
debugsql (sql): SET SESSION timezone TO 'UTC'
debugsql (sec): 0.001
debugsql (sql): SELECT "category_custom_fields"."category_id" FROM "category_custom_fields" WHERE "category_custom_fields"."name" = 'private_topics_enabled'
debugsql (sec): 0.001
debugsql (sql): SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
FROM pg_type as t
LEFT JOIN pg_range as r ON oid = rngtypid
WHERE
  t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'text', 'varchar', 'char', 'name', 'bpchar', 'bool', 'bit', 'varbit', 'date', 'money', 'bytea', 'point', 'hstore', 'json', 'jsonb', 'cidr', 'inet', 'uuid', 'xml', 'tsvector', 'macaddr', 'citext', 'ltree', 'line', 'lseg', 'box', 'path', 'polygon', 'circle', 'numeric', 'interval', 'time', 'timestamp', 'timestamptz')
debugsql (sec): 0.001
debugsql (sql): SELECT a.attname
  FROM (
         SELECT indrelid, indkey, generate_subscripts(indkey, 1) idx
           FROM pg_index
          WHERE indrelid = '"topics"'::regclass
            AND indisprimary
       ) i
  JOIN pg_attribute a
    ON a.attrelid = i.indrelid
   AND a.attnum = i.indkey[i.idx]
 ORDER BY i.idx
debugsql (sec): 0.002
debugsql (sql): SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
FROM pg_type as t
LEFT JOIN pg_range as r ON oid = rngtypid
WHERE
  t.typtype IN ('r', 'e', 'd')
debugsql (sec): 0.001
debugsql (sql): SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
FROM pg_type as t
LEFT JOIN pg_range as r ON oid = rngtypid
WHERE
  t.typelem IN (16, 17, 18, 19, 20, 21, 23, 25, 26, 114, 142, 600, 601, 602, 603, 604, 628, 700, 701, 718, 790, 829, 869, 650, 1042, 1043, 1082, 1083, 1114, 1184, 1186, 1560, 1562, 1700, 2950, 3614, 3802, 16924, 88307, 88314, 106343, 106350, 13223, 13226, 13228, 13234, 13236, 3904, 3906, 3908, 3910, 3912, 3926)
debugsql (sec): 0.001
debugsql (sec): 0.009
debugsql (sql): SELECT a.attname
  FROM (
         SELECT indrelid, indkey, generate_subscripts(indkey, 1) idx
           FROM pg_index
          WHERE indrelid = '"posts"'::regclass
            AND indisprimary
       ) i
  JOIN pg_attribute a
    ON a.attrelid = i.indrelid
   AND a.attnum = i.indkey[i.idx]
 ORDER BY i.idx
debugsql (sec): 0.007
debugsql (sql): SELECT a.attname, format_type(a.atttypid, a.atttypmod),
       pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
       c.collname, col_description(a.attrelid, a.attnum) AS comment,
       attidentity AS identity,
       attgenerated as attgenerated
  FROM pg_attribute a
  LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
  LEFT JOIN pg_type t ON a.atttypid = t.oid
  LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
 WHERE a.attrelid = '"topics"'::regclass
   AND a.attnum > 0 AND NOT a.attisdropped
 ORDER BY a.attnum
debugsql (sec): 0.002
debugsql (sql): SELECT COUNT(*) AS "count_all", date(posts.created_at) AS "date_posts_created_at" FROM "posts" INNER JOIN "topics" ON "topics"."deleted_at" IS NULL AND "topics"."id" = "posts"."topic_id" WHERE "posts"."deleted_at" IS NULL AND (topics.archetype <> 'private_message') AND NOT ((topics.category_id IN (NULL))) AND (posts.created_at >= '2025-03-03 06:42:19.865947' AND posts.created_at <= '2025-03-31 06:42:19.866261') AND "posts"."post_type" = 1 GROUP BY date(posts.created_at) ORDER BY date(posts.created_at)
debugsql (sec): 0.002
debugsql (sql): SELECT "category_custom_fields"."category_id" FROM "category_custom_fields" WHERE "category_custom_fields"."name" = 'private_topics_enabled'
debugsql (sec): 0.0
debugsql (sql): SELECT COUNT(*) FROM "posts" INNER JOIN "topics" ON "topics"."deleted_at" IS NULL AND "topics"."id" = "posts"."topic_id" WHERE "posts"."deleted_at" IS NULL AND (topics.archetype <> 'private_message') AND NOT ((topics.category_id IN (NULL))) AND "posts"."post_type" = 1
debugsql (sec): 0.0
debugsql (sql): SELECT COUNT(*) FROM "posts" INNER JOIN "topics" ON "topics"."deleted_at" IS NULL AND "topics"."id" = "posts"."topic_id" WHERE "posts"."deleted_at" IS NULL AND (topics.archetype <> 'private_message') AND NOT ((topics.category_id IN (NULL))) AND "posts"."post_type" = 1 AND (posts.created_at >= '2025-02-01 06:42:19.865947' and posts.created_at < '2025-03-03 06:42:19.865947')
debugsql (sec): 0.0
debugsql (sql): COMMIT
debugsql (sec): 0.0
=> []
discourse(prod)> 

The above is the output from my console.

I have installed several plugins; however, after entering safe mode in the browser, the backend still does not display the post count. I am uncertain where the issue lies, as all other statistics appear to be functioning normally—only the post count yields no results whatsoever.

「いいね!」 2

ありがとうございます。あなたのクエリにも、原因がわからない奇妙な AND NOT ((topics.category_id IN (NULL))) 句が含まれています。セーフモードでもこの問題が発生する場合、プラグインが原因ではないと除外できます。

「いいね!」 1

これはセーフモードでは無効にできないサーバー側の問題である可能性があります。

お二人とも Private Topics Plugin がインストールされているようです。それが問題である可能性があります。おそらく1月のこのコミットでしょうか? SECURITY: remove private topics category from public_posts · communiteq/discourse-private-topics@08c9668 · GitHub

「いいね!」 4

素晴らしい指摘ですね。プライベートカテゴリが設定されていない場合にプラグインがその行を挿入しないように修正することに同意します(本日中に更新します)。

しかし、それがダッシュボードを破損する可能性がある理由がわかりません。

「いいね!」 3

確信はありませんが、テストサイトにPrivate Topicsプラグインをインストールすると、この問題を再現できます。これは、カテゴリのセキュリティ設定で「プライベートトピックを有効にする」が設定されているカテゴリがない場合(プラグインがインストールされていても無効になっている場合)に発生するようです。カテゴリにプライベートトピックが有効になっていると設定すると、ダッシュボードレポートが再び表示されます。

修正されたレポートが、追加条件のNULL値を好まないのかもしれません。

「いいね!」 6

問題を再現することができ、修正をプッシュしました。

@JammyDodger ありがとうございます。これを見つけるのにどれくらい時間がかかったか分かりません。

(おかえりなさい)

「いいね!」 5

ありがとうございます!難しい問題でした…

「いいね!」 1

ありがとうございます、@JammyDodger さん。これで頭がおかしくなりそうでした :zany_face:

「いいね!」 4