Граф коммитов

1343 Коммитов

Автор SHA1 Сообщение Дата
Julien Tant
a5ea445bf9 [MM-46097] Change FileInfo count query (#20871)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2022-08-30 09:49:39 -07:00
Tim Scheuermann
eb37139f16 MM-45994 ensure database operations return their errors (#20857) 2022-08-26 11:12:59 +02:00
Shivashis Padhi
6adbcc5d05 MM-45899: Insights: least active channels (#20796)
* Add api endpoints, app layers for top inactive channels with dummy store calls

* Add store functions for top inactive channels

* Add model, store, app tests.

* Add client function and api tests

* Add participants information to TopInactiveChannel

* Translation fix

* Style fix while writing response

* Return channelmember IDs instead of profiles, query in batch avoiding inside the loop

* Make the following changes

 - move DeleteAt to subqueries, to avoid select, group by
 - Remove TeamId from response
 - Count bots and webhook posts

* SQL query lint fix, store test fix to include bot messages

* make app-layers

* Fix empty participant lists being sent as [""]

* Track channel joins, to distinguish 0 activity channels vs new channels

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2022-08-24 23:14:56 +05:30
Agniva De Sarker
8fd1762c3b MM-46503: Escape incorrect pg user search query (#20863)
There were 2 main problems after https://github.com/mattermost/mattermost-server/pull/20367.

1. The : wasn't escaped.
2. Empty search didn't work.

For 1, we escape the ':'. For 2, we just use
pattern search.

```release-note
NONE
```
2022-08-24 21:45:52 +05:30
Agniva De Sarker
492a3c0669 Warn on MariaDB servers (#20862)
```release-note
NONE
```
2022-08-23 14:17:45 +05:30
Shivashis Padhi
582812f1fc Merge branch 'master' of github.com:mattermost/mattermost-server into top-dms-clean 2022-08-12 17:00:55 +05:30
Martin Kraft
55b3961b98 MM-45120: Track team join times. Add API to retrieve new team members since a given time. (#20708)
* MM-45120: Starts tracking team join time. Adds API to retrieve team members who joined after a given time.

* MM-45120: Updates json casing to match model.User.
2022-08-11 10:38:52 -04:00
Shivashis Padhi
4ec3eade3b Merge branch 'master' of github.com:mattermost/mattermost-server into top-dms-clean 2022-08-10 21:00:57 +05:30
Mattermod
4fc8ef0125 Merge branch 'master' into MM-45118_my_top_dms 2022-08-05 09:56:52 +03:00
Shivashis Padhi
3e36894ac7 Avoid joining with Posts table while getting top user reactions 2022-08-03 15:43:09 +05:30
Shivashis Padhi
45e434cc26 Fix issue with pagination where has_next is false for every case 2022-08-03 13:28:03 +05:30
Agniva De Sarker
334b199e7a Optimize AnalyticsPostCount (#20727)
We use * instead of a column name to use
index-only scan always even when other column filters
are applied.

Right now, index-only scan will only get applied
in the basic query of "select count(p.id) as value
from posts p". But it won't get applied if the query
is "select count(p.id) as value from posts p where
p.deleteat=0".

So this is a minor optimization which improves
some corner cases.

This was found from the slow query monitoring.

```release-note
NONE
```
2022-08-03 10:31:18 +05:30
Vishal
fa768e0fa7 [MM-45726] Fix Sentry crash: nil deference in app/post_helpers.go:85 (#20654)
* Avoid adding duplicate post
2022-08-02 12:10:26 +05:30
Dimitris Oik
8444c45959 MM-44576 autocomplete names including utf 8 chars (#20367)
* Added unaccent extension

* Changed comment

* Deletes migrations, changes query method

* Mionr changes

* Creates test for multilingual queries

* Minor formatting changes

* Adds two more tests

* Changes name in test function

* Minor change

* Retriggers tests

* Removes % from Postgres query

* Lint fix

* Changes variable name

* Removes SetDefaultTextSearchConfig method

* Removes mocks

* Adds error handling on test raw queries

* Lint fix

* Deletes unused generated file

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2022-08-01 06:58:31 -04:00
Shivashis Padhi
61a716a98c Fix Posts query while populating top DMs, add OutgoingMessageCount check to tests 2022-08-01 13:58:50 +05:30
Kyriakos Z
562388501e MM-43939: fixes LastReplyAt when deleting the last reply (#20615)
* MM-43939: fixes lastreplyat when deleting the last reply

Currently we are not updating the Threads.LastReplyAt when the last
reply gets deleted. This can lead to threads appearing unread when
actually there is no unread thread.

This commit updates the value of Threads.LastReplyAt when a reply gets
deleted, to the most recent post's timestamp in the thread.

* Updates ReplyCount to current value on post delete

* Addresses review comments

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2022-07-29 10:03:52 -04:00
Shivashis Padhi
f84a6ae7ac Add TotalMsgCount to GROUP BY fields 2022-07-29 13:05:05 +05:30
Shivashis Padhi
9f468cf011 Select total message count from Channel instead of counting posts 2022-07-28 17:22:14 +05:30
Shivashis Padhi
57e25b5d8f Add information on individual message count 2022-07-28 16:36:37 +05:30
Shivashis Padhi
f007d94155 Ignore self DMs 2022-07-28 12:46:18 +05:30
Shivashis Padhi
55bf7458d7 Temporarily add second participant information for self dms 2022-07-28 12:35:17 +05:30
Shivashis Padhi
e94532c862 SecondParticipant now has extended user object 2022-07-27 18:41:18 +05:30
Shivashis Padhi
849aea452c Merge branch 'master' of github.com:mattermost/mattermost-server into top-dms-clean 2022-07-27 17:03:34 +05:30
Agniva De Sarker
20cb042362 Hackathon: Post Reminders (#20555)
This PR adds the post reminder backend work.

We add a new API endpoint via which a user can set a reminder for a post. An ephemeral message will be sent down the line to let the user know about the action. And then after the time is over, the system admin bot will send a DM message to the user about the reminder post.
2022-07-26 16:12:56 +05:30
Shivashis Padhi
870d86ae1d Save users to db in storetests, lint fix 2022-07-25 16:38:46 +05:30
Shivashis Padhi
b3330b1eb0 Fix boolean check of user.IsBot 2022-07-25 16:09:44 +05:30
Shivashis Padhi
5f56d43d80 Make the following changes
- Use db userId instead of referring to session
 - Filter out bot DM channels, and add relevant test
2022-07-25 14:07:08 +05:30
Shivashis Padhi
2b66652f69 Fix top dms query, add storetests 2022-07-21 18:41:41 +05:30
Shivashis Padhi
a8fa09f946 Fix counting of posts, remove redundant limit offset for queries 2022-07-21 18:39:23 +05:30
Shivashis Padhi
0ab2189941 Add top DMs route and handlers 2022-07-21 18:39:03 +05:30
Agniva De Sarker
abd5384d9b Clarify collation mismatch string (#20641)
We replace expected/received with the source of the collation.

This makes it more clear as to from where the values
were retrieved.

```release-note
NONE
```
2022-07-13 12:11:03 +05:30
Shivashis Padhi
20d690b412 [MM-45444] Denormalize Reactions to add ChannelId for top reactions insights query (#20572)
* Denormalize Reactions to add ChannelId for top reactions insights query

* Remove hardcoded timestamps

* Fix store, api4 tests for reactions

* Fix tests

* Fix integrity tests, allow reaction to have ChannelId populated before calling store function

* Lint fixes

* Add ChannelId field to BulkGetForPosts, Delete store handlers

* Add index to mysql migration, add not null characteristic without a separate command

* Select channelId instead of fetching post via store.GetPost, add if exists to drop column

* Make updating of Reactions conditional to support pre-migration

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2022-07-11 09:25:03 -04:00
Martin Kraft
a46840e96b MM-45395: Exclude bot and webhook posts from Top Team Channels. Exclude webhook posts from My Top Channels. (#20599)
* MM-45395: Exclude bot and webhook posts from Top Team Channels. Exclude webhook posts from My Top Channels.

* MM-45395: Adds missing error test.

* MM-45395: Adds missing whitespace.
2022-07-11 08:58:40 -04:00
Vishal
e5ee5eecd8 [MM-44488] Cloud limits: enforcing messages (#20362)
* Add new Job to keep updating the last_accessible_post time

* Filter out posts for funcs returning PostList model

* Separate methods to get and compute cache

* filter pinned posts

* For posts with sorted CreateAt order, support a faster form of filtering.

* Add inaccessible header for getPost and getPostsByIDs APIs

* replace manual binary search with the std. library

* in-place filter posts

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Nathaniel Allred <neallred@protonmail.com>
2022-07-06 11:56:39 +05:30
Ibrahim Serdar Acikgoz
717a4d04a9 Use any instead of interface{} (#20577)
* replace interface{} with any
2022-07-05 09:46:50 +03:00
Julien Tant
b45ff0be5d [MM-44159] Add user sort by admin status in channels (#20562) 2022-06-30 09:20:14 -07:00
Agniva De Sarker
bd6acf04a9 GraphQL: Create dedicated top-level filter for sidebar categories (#20353)
We add the excludeTeam switch to allow user to get
all sidebar categories from other teams excluding a given team.

```release-note
NONE
```
2022-06-28 20:28:50 +05:30
Shivashis Padhi
2cd83d2f8d [MM-44084] Feature: Top threads insights (#20195)
* Add route endpoints, model, store functions, and tests for top threads

* Run make store-layers

* Make the following changes

 - Fix top user threads query
 - Fix passing parameters in api4/insights.go to handler in app
 - Add top user threads test

* Add post-message, user_id, participants information to insights results

* model.TopThread.UserID -> model.TopThread.UserId, for compatibility with MySQL

* Rename name -> channel_name

* Add user information to response

* Link post in response, filter out deleted root posts from top threads

* Handle thread delete cases, add app tests for threads insights

* lint: fix typo

* lint: rename asserts

* lint: require.nil -> require.NoError

* Add integration tests for thread insights

* Add embeds and images to top posts

* Add license checks for top threads endpoints

* Query users in batch to populate post-creator

* Make the following changes

 - Add license to test server in api4/
 - Add tests for threads insights
    - top team threads shouldn't include threads from other teams, DMs
    - Test duration constraint
    - Pagination testing for top threads in model/insights_test.go

* Add i18n-extract

* i18n fixes

* Add username, nickname to user_information

* Hide message, user_id, post_id, reply_count in depth=1 of top threads response

* Fix tests using response.reply_count to use response.post.reply_count

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2022-06-20 10:27:17 -04:00
Agniva De Sarker
18c8a2bb53 MM-25554: Remove hardcoded english as the search config (#20472)
We use the default_text_search_config param from the DB
and pass that as the search config instead of hardcoding
it to english.

The docs do say that if no param is passed, by default
it will automatically fall back to default_text_search_config.
But I have seen different query plans being created
when the parameter is not passed versus when it is passed.
I am not sure why this is happening, but to be safe,
I have taken the search config during startup and stored
it in the SqlStore struct.

For reference, this is what happens without a search config
passed:

```
[bigdb] # explain analyze  SELECT *, (SELECT COUNT(*) FROM Posts WHERE Posts.RootId = (CASE WHEN q2.RootId = '' THEN q2.Id ELSE q2.RootId END) AND Posts.DeleteAt = 0) as ReplyCount FROM Posts q2 WHERE q2.DeleteAt = 0 AND q2.Type NOT LIKE 'system_%' AND to_tsvector(Message) @@  to_tsquery('sapiente') AND ChannelId IN (SELECT Id FROM Channels, ChannelMembers WHERE Id = ChannelId AND Channels.DeleteAt = 0 AND ChannelMembe
                                                                                                                                                                                                                                                                                                                               rs.UserId = 'tc3p1yqw67d8idcp3g98awexqe' AND (TeamId = '8ywxyw9ocp8smxrmjzrkqhrdwe' OR TeamId = '') AND Id IN ('h1x9asxr7idjpqfmg8q67us49h')) ORDER BY q2.CreateAt DESC LIMIT 100;
                                                                                                  QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=8200.93..8720.23 rows=9 width=382) (actual time=177.277..177.948 rows=100 loops=1)
   ->  Result  (cost=8200.93..8720.23 rows=9 width=382) (actual time=177.274..177.939 rows=100 loops=1)
         ->  Sort  (cost=8200.93..8200.95 rows=9 width=374) (actual time=177.245..177.271 rows=100 loops=1)
               Sort Key: q2.createat DESC
               Sort Method: top-N heapsort  Memory: 161kB
               ->  Nested Loop Semi Join  (cost=71.53..8200.79 rows=9 width=374) (actual time=5.910..176.815 rows=532 loops=1)
                     ->  Bitmap Heap Scan on posts q2  (cost=70.56..8183.64 rows=9 width=374) (actual time=5.815..176.457 rows=532 loops=1)
                           Recheck Cond: ((channelid)::text = 'h1x9asxr7idjpqfmg8q67us49h'::text)
                           Filter: (((type)::text !~~ 'system_%'::text) AND (deleteat = 0) AND (to_tsvector((message)::text) @@ to_tsquery('sapiente'::text)))
                           Rows Removed by Filter: 5244
                           Heap Blocks: exact=944
                           ->  Bitmap Index Scan on idx_posts_channel_id_update_at  (cost=0.00..70.56 rows=1866 width=0) (actual time=1.883..1.883 rows=5776 loops=1)
                                 Index Cond: ((channelid)::text = 'h1x9asxr7idjpqfmg8q67us49h'::text)
                     ->  Materialize  (cost=0.98..17.04 rows=1 width=27) (actual time=0.000..0.000 rows=1 loops=532)
                           ->  Nested Loop  (cost=0.98..17.03 rows=1 width=27) (actual time=0.080..0.080 rows=1 loops=1)
                                 ->  Index Scan using channels_pkey on channels  (cost=0.42..8.45 rows=1 width=27) (actual time=0.041..0.042 rows=1 loops=1)
                                       Index Cond: ((id)::text = 'h1x9asxr7idjpqfmg8q67us49h'::text)
                                       Filter: ((deleteat = 0) AND (((teamid)::text = '8ywxyw9ocp8smxrmjzrkqhrdwe'::text) OR ((teamid)::text = ''::text)))
                                 ->  Index Only Scan using idx_channelmembers_user_id_channel_id_last_viewed_at on channelmembers  (cost=0.56..8.58 rows=1 width=27) (actual time=0.034..0.034 rows=1 loops=1)
                                       Index Cond: ((userid = 'tc3p1yqw67d8idcp3g98awexqe'::text) AND (channelid = 'h1x9asxr7idjpqfmg8q67us49h'::text))
                                       Heap Fetches: 1
         SubPlan 1
           ->  Aggregate  (cost=57.68..57.69 rows=1 width=8) (actual time=0.006..0.006 rows=1 loops=100)
                 ->  Index Only Scan using idx_posts_root_id_delete_at on posts  (cost=0.56..54.44 rows=1294 width=0) (actual time=0.005..0.005 rows=3 loops=100)
                       Index Cond: ((rootid = (CASE WHEN ((q2.rootid)::text = ''::text) THEN q2.id ELSE q2.rootid END)::text) AND (deleteat = 0))
                       Heap Fetches: 0
 Planning Time: 2.178 ms
 Execution Time: 178.155 ms
```

We can see it using a top-N heapsort.

And this is what happens when an explicit search config
is passed:

```
[bigdb] # explain analyze  SELECT *, (SELECT COUNT(*) FROM Posts WHERE Posts.RootId = (CASE WHEN q2.RootId = '' THEN q2.Id ELSE q2.RootId END) AND Posts.DeleteAt = 0) as ReplyCount FROM Posts q2 WHERE q2.DeleteAt = 0 AND q2.Type NOT LIKE 'system_%' AND to_tsvector('pg_catalog.english', Message) @@  to_tsquery('pg_catalog.english', 'sapiente') AND ChannelId IN (SELECT Id FROM Channels, ChannelMembers WHERE Id = ChannelId AND Channels.DeleteAt = 0 AND ChannelMembers.UserId = 'tc3p1yqw67d8idcp3g98awexqe' AND (TeamId = '8ywxyw9ocp8smxrmjzrkqhrdwe' OR TeamId = '') AND Id IN ('h1x9asxr7idjpqfmg8q67us49h')) ORDER BY q2.CreateAt DESC LIMIT 100;
                                                                                            QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=1.54..10679.04 rows=100 width=382) (actual time=0.237..31.405 rows=100 loops=1)
   ->  Nested Loop Semi Join  (cost=1.54..17512.64 rows=164 width=382) (actual time=0.236..31.387 rows=100 loops=1)
         ->  Index Scan Backward using idx_posts_channel_id_delete_at_create_at on posts q2  (cost=0.56..8032.81 rows=164 width=374) (actual time=0.121..30.124 rows=100 loops=1)
               Index Cond: (((channelid)::text = 'h1x9asxr7idjpqfmg8q67us49h'::text) AND (deleteat = 0))
               Filter: (((type)::text !~~ 'system_%'::text) AND (to_tsvector('english'::regconfig, (message)::text) @@ '''sapient'''::tsquery))
               Rows Removed by Filter: 1088
         ->  Materialize  (cost=0.98..17.04 rows=1 width=27) (actual time=0.001..0.001 rows=1 loops=100)
               ->  Nested Loop  (cost=0.98..17.03 rows=1 width=27) (actual time=0.074..0.075 rows=1 loops=1)
                     ->  Index Scan using channels_pkey on channels  (cost=0.42..8.45 rows=1 width=27) (actual time=0.032..0.032 rows=1 loops=1)
                           Index Cond: ((id)::text = 'h1x9asxr7idjpqfmg8q67us49h'::text)
                           Filter: ((deleteat = 0) AND (((teamid)::text = '8ywxyw9ocp8smxrmjzrkqhrdwe'::text) OR ((teamid)::text = ''::text)))
                     ->  Index Only Scan using idx_channelmembers_user_id_channel_id_last_viewed_at on channelmembers  (cost=0.56..8.58 rows=1 width=27) (actual time=0.041..0.041 rows=1 loops=1)
                           Index Cond: ((userid = 'tc3p1yqw67d8idcp3g98awexqe'::text) AND (channelid = 'h1x9asxr7idjpqfmg8q67us49h'::text))
                           Heap Fetches: 1
         SubPlan 1
           ->  Aggregate  (cost=57.68..57.69 rows=1 width=8) (actual time=0.010..0.010 rows=1 loops=100)
                 ->  Index Only Scan using idx_posts_root_id_delete_at on posts  (cost=0.56..54.44 rows=1294 width=0) (actual time=0.009..0.009 rows=3 loops=100)
                       Index Cond: ((rootid = (CASE WHEN ((q2.rootid)::text = ''::text) THEN q2.id ELSE q2.rootid END)::text) AND (deleteat = 0))
                       Heap Fetches: 0
 Planning Time: 0.401 ms
 Execution Time: 31.466 ms
```

https://mattermost.atlassian.net/browse/MM-25554

```release-note
NONE
```
2022-06-17 19:52:56 +05:30
Riccardo Santoni
dd7067cbe9 [MM-44434] Introduced search for channel id's through system console. (#20259)
* Introduced search for channel id's

* Small fix to test case as it is not looking at count

* Introduced searching channels by id as a ChannelOpt. Defaulting to true for system console for the time being

* go fmt

* Modified whether to include search by id by passing it in as prop to search endpoint. Modified webapp to pass through search by id as well

* Fixed issue with full text search, as there is not always necessarily an index on Id.

* Modified test to verify count, and moved code inside conditional

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2022-06-16 11:32:16 -04:00
Martin Kraft
4e9edef1f1 Improves group membership telemetry. (#20437)
* Improves groups membership telemetry.

* Removes unnecessary where clause (it's added by default).

* Cleans up data.

* Testing the relative group counts.

* Adds missing test mock.

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2022-06-15 09:42:27 -04:00
Nathaniel Allred
90c737a57a File storage usage default 0 (#20454)
* check for test fail in CI

* use 0 if there are no fileinfo table entries

* fix usage
2022-06-15 12:43:01 +05:30
Martin Kraft
182ae1234a MM-43956: Adds post counts by duration. (#20131)
* MM-43956: Adds post counts by day.

* MM-43956: Test data cleanup. Switch from Unix to UnixMilli.

* MM-43956: Changes from selecting date data types to strings in SQL.

* MM-43956: Fixes date format key.

* MM-43956: Adds missing user id scope for 'my' top channels graph.

* MM-43956: Adds the ability to group post counts by hour.

* MM-43956: Require enterprise or professional license. Reject guests.

* MM-43956: Adds license for tests.

* MM-43956: Renames function.

* MM-43956: Omits future hours from post counts by hour.

* MM-43956: Adjust API response grouping to users timezone.

* MM-43956: Adds translation.

* MM-43956: Adds user's timezone to the data tier for the grouping by day and hour.

* MM-43956: Fixes layers.

* MM-43956: Lint fix.

* MM-43956: Fix store layers.

* MM-43956: Switches to default name for time package; changes parameter names to avoid naming conflict.

* MM-43956: Updates mocks.

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2022-06-13 16:22:34 -04:00
Guillermo Vayá
c6f80dfe0a [MM-44573] Sanitize options (#20380)
Automatic Merge
2022-06-09 00:36:28 +03:00
Tim Scheuermann
f836826c1d [MM-44329] Add a method to store.Store interface to get sql.DB object (#20351)
* [MM-44329] Added methods to sqlstore.Store

* [MM-44329] Added methods to the store.Store interface

* [MM-44329] Regenerated mocks

* [MM-44329] Added comments for the store.Store interface

Co-authored-by: Tim Scheuermann <tim.scheuermann@mattermost.com>
2022-06-03 11:11:23 +02:00
Ashish Bhate
8f912b697e MM-43918: freemium limit for storage (#20225)
Summary
Adds an API end point to return storage usage

Ticket Link
https://mattermost.atlassian.net/browse/MM-43918
2022-06-03 11:48:29 +05:30
Agniva De Sarker
ec0284b459 MM-44638: Remove upgrade.go (#20309)
We remove any remaining migrations from the upgrade.go file

```release-note
NONE
```
2022-06-02 22:53:12 +05:30
Ibrahim Serdar Acikgoz
fe3816cc20 store: guests will only receive results of which channels they are in (#20295)
* store: guests will only receive results of which channels they are in

* api4/channel_test: add test case for guest accounts channel autocomplete

* apply to searchengine and also for AutocompleteInTeam

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2022-06-01 09:18:59 +03:00
Joram Wilander
8b1a6ef238 Remove NextSyncAt from GetRemoteStatus query (#20312) 2022-05-31 11:03:10 -04:00
Vishal
57e9aa767c [MM-44263] Only include user posts in post count (#20250)
* Fetch users only posts

* Explicitly validate posts count before testing usage
2022-05-31 14:18:41 +05:30