Estatísticas de Novas Postagens no Dashboard estão quebradas

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

Muitos… :wink: Retirado do YAML de configuração do contêiner:

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

Aliás, como @qingfeng1024 também está a experienciar este problema, não parece ser um problema pessoal aqui. Talvez ele também possa nos dizer o que os testes acima mostram no/no fórum lá e também quais plugins são usados?

2 curtidas

@martin você tem alguma ideia sobre este problema?

1 curtida

Não, desculpe, isso passou um pouco despercebido.

@qingfeng1024 acontece exatamente a mesma coisa com você se você executar isso no seu console do rails?

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

Você verá uma saída como esta postagem, você pode copiar e colar aqui por favor? Dashboard New Posts statistics broken - #18 by Roi

@kris.kotlarek Não tive sorte aqui, você consegue ver se algo se destaca para você neste tópico?

2 curtidas
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 curtidas

Obrigado! Suas consultas têm a mesma cláusula estranha AND NOT ((topics.category_id IN (NULL))) que não consigo descobrir a origem. Pelo menos podemos descartar plugins se isso acontecer em modo de segurança também.

1 curtida

Acho que pode ser um problema do lado do servidor que o modo de segurança não desabilita.

Parece que ambos têm o plugin Private Topics Plugin instalado. Acho que pode ser um problema com ele. Possivelmente este commit de janeiro? SECURITY: remove private topics category from public_posts · communiteq/discourse-private-topics@08c9668 · GitHub

4 curtidas

Boa observação e concordo que o plugin não deveria inserir essa linha se não houver categorias privadas definidas (atualizarei ainda hoje)

Mas não consigo ver como isso pode quebrar o painel?

3 curtidas

Não tenho certeza, mas quando instalo o plugin Private Topics no meu site de teste, consigo reproduzir este problema. Parece acontecer quando não tenho nenhuma categoria definida com ‘habilitar tópicos privados’ nas configurações de segurança da categoria (mesmo que o plugin esteja instalado, mas desativado). Se eu definir uma categoria para ter Tópicos Privados habilitados, meu relatório do painel é preenchido novamente.

Acho que pode ser que o relatório alterado não goste do valor NULL na condição extra?

6 curtidas

Consegui reproduzir o problema e fiz um correção.

Obrigado @JammyDodger, não tenho certeza de quanto tempo teria levado para eu encontrar isso.

(Bom te ver de volta)

5 curtidas

Ótimo, obrigado a todos! Esse foi difícil de resolver…

1 curtida

Ah, incrível, obrigado @JammyDodger, isso estava me deixando louco :zany_face:

4 curtidas