Get channel statistics API become slow after upgraded

Hello,

I recently upgraded my Mattermost server from version 5.31.0 to 7.9.1, and I noticed that the API endpoint “Get channel statistics” has become significantly slower, taking 20 times longer than before:

In v5.31.0: 77 ms with 565 B of response size
In v7.9.1: 1525 ms with 525 B of response size

I’m wondering if there are any possible solutions to fix this performance issue?

Thanks.

Hi @YiruChen ,

can you look at the query that is being executed in the database while you access this API endpoint? What database are you using? MySQL or PostgreSQL?

I’m using PostgreSQL postgres:12-alpine

Where can I find this log?

That’s not a log, but you would need to be connected to your PostgreSQL instance and run the following query after you’ve started the API call:

select pid,backend_start,query_start,state_change,waiting,state,query from pg_stat_activity;

this will show you a list of currently running queries, maybe one of them is slow - you can run the queries on the command line then to see which one of them is the slow one.

Sorry I cannot find out which query is related to the API.

I found that the v5.31.0 response is like this:
{
“channel_id”: “xxxxxx”,
“member_count”: 7,
“guest_count”: 0,
“pinnedpost_count”: 0
}

v7.9.1 is like this:
{
“channel_id”: “xxxxxx”,
“member_count”: 7,
“guest_count”: 0,
“pinnedpost_count”: 0,
“files_count”: 0
}

Does the presence or absence of the “files_count” field cause the problem?

I think it’s the problem, after setting exclude_files_count=true, the performance became better. (47 ms 526 B)

Alright, nice finding - the file count is obviously new here and requires querying additional tables which results in longer execution times. Good to hear that by restoring the previous behaviour you’re able to achieve the same speeds again.

I would like to ask how to set exclude_flies_count = true,

its a query parameter of this API

curl --location '{{your-mattermost}}/api/v4/channels/{{channel-id}}/stats?exclude_files_count=true' \

--header 'Authorization: Bearer {{your-token}}'

I know it can be done in the api, but I want to attach this parameter to the request sent by the client. Is there any setting options such as the system console?