仪表盘新帖统计数据损坏

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)=>

A lot… :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 console 中运行这个,你是否会遇到完全相同的问题?

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 个赞

我认为这可能是服务器端的问题,安全模式无法禁用。

看起来你们都安装了 https://meta.discourse.org/t/private-topics-plugin/268646。我认为这可能是该插件的问题。可能是1月份的这个提交?https://github.com/communiteq/discourse-private-topics/commit/08c966890319b4d9a0647ab0b2bdba68097bfaac

4 个赞

抓得好,我同意如果没有设置私有类别,插件就不应该插入那一行(稍后会更新)。

但我看不出它怎么会破坏仪表板?

3 个赞

我不完全确定,但当我将 Private Topics 插件安装到我的测试站点时,我可以重现此问题。似乎是在类别安全设置中没有设置任何类别启用“启用私有主题”(即使已安装插件但已禁用)。如果我将一个类别设置为启用私有主题,那么我的仪表板报告就会再次填充。

我认为可能是修改后的报告不喜欢额外条件中的 NULL 值?

6 个赞

我已经能够重现该问题,并且已经推送了一个修复程序

谢谢你 @JammyDodger,我不确定我需要多长时间才能找到它。

(很高兴看到你回来)

5 个赞

太好了,谢谢大家!这真是一个很难解决的问题……

1 个赞

啊,太棒了,谢谢你 @JammyDodger ,这让我抓狂 :zany_face:

4 个赞