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

1219 Коммитов

Автор SHA1 Сообщение Дата
Spiros Economakis
5fa8499602 Update database to v6.4.0 (#19500) 2022-02-04 15:34:10 +02:00
Agniva De Sarker
a733fb840d GraphQL (part 1): Store layer (#19465)
We add the necessary store methods to use GraphQL

```release-note
NONE
```
2022-02-02 22:44:22 +05:30
Agniva De Sarker
6e97d581e4 PostStore: Remove db:"-" tag and some other hacks (#19384)
Before gorp, to use sqlx we had to resort to using
internal structs without the `db:"-"` tag so that
it doesn't interfere with the gorp table generation.

Now that it's gone, we can use the original model structs.

```release-note
NONE
```
2022-01-31 23:08:30 +05:30
Ashish Bhate
7026818f80 MM-35298: Follow thread when added to channel (#19311)
* MM-35298: Follow thread when added to channel

* return better error if thread doesn't exist

* update test for possible race

* use correct comparision operator
2022-01-25 14:44:18 -05:00
Kirill Krotov
e2e049e05e [MM-39633] migrate team store to sqlx (#19207)
```release-note
NONE
```

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
2022-01-25 23:03:47 +05:30
Josh Soref
294bd44971 [GH-19267] Spelling comments (#19268)
* spelling: comments

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2022-01-20 10:07:27 +05:30
Ibrahim Serdar Acikgoz
509f49c813 Remove unused store/sqlstore functions (#19354) 2022-01-18 09:00:58 +03:00
Agniva De Sarker
4ca6539e03 channel_store: update TODO items with issues (#19337)
```release-note
NONE
```
2022-01-14 12:41:41 +05:30
Agniva De Sarker
b37c07ec41 Migrate channel_store to sqlx (#19247)
* Migrate channel_store to sqlx

https://community-daily.mattermost.com/boards/workspace/zyoahc9uapdn3xdptac6jb69ic/285b80a3-257d-41f6-8cf4-ed80ca9d92e5/495cdb4d-c13a-4992-8eb9-80cfee2819a4/chur9rxkghprg7dz1mcqssj34ic

```release-note
NONE
```
2022-01-14 10:43:54 +05:30
Ibrahim Serdar Acikgoz
f829dba615 Update morph dependency (#19308)
* Update morph dependency to use a newer version

* remove timeout check for migrations statements

* store/sqlstore: reset timeout for mysql while creating db for migrations

* update morph to v0.2.1
2022-01-12 17:24:29 +03:00
Ashish Bhate
a55bd001b4 Revert "[MM-37013] Async job to fix CRT channel unreads (#18340)" (#19319)
This reverts commit 0da249c651.
2022-01-12 18:51:47 +05:30
Ibrahim Serdar Acikgoz
d0724d8b00 migrations: Fix typos/errors and add missing migrations (#19316)
* fix public channels creation script for mysql

* fix several remaining migrations
2022-01-12 16:19:03 +03:00
Ashish Bhate
ec22cf9a08 [MM-37013]: Fix store get for null columns (#19310)
Automatic Merge
2022-01-11 16:29:52 +02:00
Ibrahim Serdar Acikgoz
6595b31f23 Replace go-migrate with morph (#19116) 2022-01-08 10:16:07 +02:00
Agniva De Sarker
2f58c88f1b MM-40594: Fix nil retention policies (#19285)
Due to the store method having named returns, the variable
was getting set to nil instead of being an empty slice.
We missed this during code review.

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

```release-note
NONE
```
2022-01-06 12:30:01 +05:30
Agniva De Sarker
95fd120670 MM-40799: Improve ReplyCount query (#19274)
* MM-40799: Improve ReplyCount query

This PR optimizes the reply count query to use only
the indexed column to count the rows rather than using
the ID column. This results in an index-only scan
rather than an index scan. As a result, the query
can be satisfied directly by scanning the index
and there is no need to touch the heap.

Count(*) also gives the same result, but is not recommended
as it also verifies non-null columns and can take slightly
longer.

Before:
```
explain analyze SELECT p.*, (SELECT COUNT(Posts.Id) FROM Posts WHERE Posts.RootId = (CASE WHEN p.RootId = '' THEN p.Id ELSE p.RootId END) AND Posts.DeleteAt = 0) AS ReplyCount FROM Posts p WHERE (CreateAt < (SELECT CreateAt FROM Posts WHERE Id = 'bguxt6zzcjytpffgza3dc7xody') AND p.ChannelId = '5xmynf36cinrzksuzhq7my1nbc' AND DeleteAt = 0) ORDER BY p.ChannelId, DeleteAt, CreateAt DESC LIMIT 30 OFFSET 0;
                                                                                 QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=9.14..130616.04 rows=30 width=922) (actual time=19.208..19.454 rows=30 loops=1)
   InitPlan 2 (returns $2)
     ->  Index Scan using posts_pkey on posts posts_1  (cost=0.56..8.58 rows=1 width=8) (actual time=0.028..0.030 rows=1 loops=1)
           Index Cond: ((id)::text = 'bguxt6zzcjytpffgza3dc7xody'::text)
   ->  Index Scan Backward using idx_posts_channel_id_delete_at_create_at on posts p  (cost=0.56..2720977.61 rows=625 width=922) (actual time=0.075..0.317 rows=30 loops=1)
         Index Cond: (((channelid)::text = '5xmynf36cinrzksuzhq7my1nbc'::text) AND (deleteat = 0) AND (createat < $2))
         SubPlan 1
           ->  Aggregate  (cost=4349.49..4349.50 rows=1 width=8) (actual time=0.007..0.007 rows=1 loops=30)
                 ->  Index Scan using idx_posts_root_id_delete_at on posts  (cost=0.56..4346.36 rows=1253 width=27) (actual time=0.007..0.007 rows=0 loops=30)
                       Index Cond: (((rootid)::text = (CASE WHEN ((p.rootid)::text = ''::text) THEN p.id ELSE p.rootid END)::text) AND (deleteat = 0))
```

After:

```
explain analyze SELECT p.*, (SELECT COUNT(Posts.RootId) FROM Posts WHERE Posts.RootId = (CASE WHEN p.RootId = '' THEN p.Id ELSE p.RootId END) AND Posts.DeleteAt = 0) AS ReplyCount FROM Posts p WHERE (CreateAt < (SELECT CreateAt FROM Posts WHERE Id = 'bguxt6zzcjytpffgza3dc7xody') AND p.ChannelId = '5xmynf36cinrzksuzhq7my1nbc' AND DeleteAt = 0) ORDER BY p.ChannelId, DeleteAt, CreateAt DESC LIMIT 30 OFFSET 0;
                                                                                 QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=9.14..130616.04 rows=30 width=922) (actual time=12.936..13.188 rows=30 loops=1)
   InitPlan 2 (returns $2)
     ->  Index Scan using posts_pkey on posts posts_1  (cost=0.56..8.58 rows=1 width=8) (actual time=0.029..0.030 rows=1 loops=1)
           Index Cond: ((id)::text = 'bguxt6zzcjytpffgza3dc7xody'::text)
   ->  Index Scan Backward using idx_posts_channel_id_delete_at_create_at on posts p  (cost=0.56..2720977.61 rows=625 width=922) (actual time=0.076..0.324 rows=30 loops=1)
         Index Cond: (((channelid)::text = '5xmynf36cinrzksuzhq7my1nbc'::text) AND (deleteat = 0) AND (createat < $2))
         SubPlan 1
           ->  Aggregate  (cost=4349.49..4349.50 rows=1 width=8) (actual time=0.008..0.008 rows=1 loops=30)
                 ->  Index Only Scan using idx_posts_root_id_delete_at on posts  (cost=0.56..4346.36 rows=1253 width=8) (actual time=0.007..0.007 rows=0 loops=30)
                       Index Cond: ((rootid = (CASE WHEN ((p.rootid)::text = ''::text) THEN p.id ELSE p.rootid END)::text) AND (deleteat = 0))
                       Heap Fetches: 14
```

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

```release-note
NONE
```

* Use COUNT(*) for faster

```release-note
NONE
```
2022-01-05 10:27:40 +05:30
Agniva De Sarker
926e7c3b5e MM-40801: Use replica for getPostsAround (#19273)
This query deals with posts already created,
and it was originally already querying replica.

In recent performance investigations, this came up
a lot of times. I believe the change to query master
was unintentional.

```release-note
NONE
```
2022-01-04 22:37:19 +05:30
Ibrahim Serdar Acikgoz
8523a2e7c1 move removal of AcceptedTermsOfServiceId from users table to 6.3 2022-01-04 17:05:51 +03:00
Ibrahim Serdar Acikgoz
4ce7d993a4 Merge pull request #19263 from mattermost/MM-40778-migration
Remove AcceptedTermsOfServiceId from Users table
2022-01-03 22:16:46 +03:00
Ibrahim Serdar Acikgoz
0d9f0e4766 Update store/sqlstore/upgrade.go
Co-authored-by: Claudio Costa <cstcld91@gmail.com>
2022-01-03 21:51:04 +03:00
Agniva De Sarker
cfcdce9ae7 Migrate post_store to sqlx (#19241)
* Migrate post_store to sqlx

There are several queries which should improve further
if re-written with squirrel. HW tickets will be opened
for those.

https://community-daily.mattermost.com/boards/workspace/zyoahc9uapdn3xdptac6jb69ic/285b80a3-257d-41f6-8cf4-ed80ca9d92e5/495cdb4d-c13a-4992-8eb9-80cfee2819a4/ctnryw9mga7fu9kc16xsap4phuw

```release-note
NONE
```

* Remove struct

```release-note
NONE
```

* fix tests

```release-note
NONE
```
2022-01-03 10:40:16 +05:30
Ibrahim Serdar Acikgoz
aa7eb64ff7 remove AcceptedTermsOfServiceId from users table 2021-12-30 18:32:24 +03:00
Ibrahim Serdar Acikgoz
6c42d2816d Merge pull request #19196 from mattermost/MM-39542
[MM-39542] Allow upsert for duplicate key in LinkMetadataStore
2021-12-22 16:31:59 +03:00
Carlos Tadeu Panato Junior
3b89080863 upgrade db to 6.3.0 (#19217) 2021-12-22 12:41:48 +01:00
Kirill Krotov
0dbc74f6d5 [GH-18965] - Pass expire time from outside Cleanup method (#19008)
Pass expire time from outside Cleanup method

Fixes #18965
2021-12-22 14:57:30 +05:30
Ben Schumacher
34c4e543f9 [MM-39999] Increase key length in plugin KV store to 150 (#19002) 2021-12-20 13:13:50 +01:00
Agniva De Sarker
87bf8fb9e9 Force right index for post deletion (#19191)
During v6 indexing changes, we replaced
idx_posts_root_id with idx_posts_root_id_delete_at.
This causes MySQL to trigger the index_merge path
again with PRIMARY and idx_posts_root_id_delete_at
as shown below:

```
mysql> UPDATE Posts SET DeleteAt = 1637998911685, UpdateAt = 1637998911685, Props = JSON_SET(Props, '$.deleteBy', 'buqskqrwmjnhfuqskqrwmjn4ca') Where Id = 'q38uaydtpink5f4wkmcsn8h47o' OR RootId = 'q38uaydtpink5f4wkmcsn8h47o';
Query OK, 9 rows affected (17.29 sec)
Rows matched: 10  Changed: 9  Warnings: 0
mysql> EXPLAIN UPDATE Posts SET DeleteAt = 1637998911685, UpdateAt = 1637998911685, Props = JSON_SET(Props, '$.deleteBy', 'buqskqrwmjnhfuqskqrwmjn4ca') Where Id = 'q38uaydtpink5f4wkmcsn8h47o' OR RootId = 'q38uaydtpink5f4wkmcsn8h47o'\G
*************************** 1. row ***************************
           id: 1
  select_type: UPDATE
        table: Posts
   partitions: NULL
         type: index_merge
possible_keys: PRIMARY,idx_posts_root_id_delete_at
          key: idx_posts_root_id_delete_at,PRIMARY
      key_len: 107,106
          ref: NULL
         rows: 9
     filtered: 100.00
        Extra: Using sort_union(idx_posts_root_id_delete_at,PRIMARY); Using where; Using temporary
1 row in set, 1 warning (0.00 sec)
```

To fix the temporary sort, we order by Id

```
mysql> UPDATE Posts SET DeleteAt = 1637998911686, UpdateAt = 1637998911686, Props = JSON_SET(Props, '$.deleteBy', 'buqskqrwmjnhfuqskqrwmjn4ca') Where Id = 'q38uaydtpink5f4wkmcsn8h47o' OR RootId = 'q38uaydtpink5f4wkmcsn8h47o' ORDER BY Id;
Query OK, 9 rows affected (0.01 sec)
Rows matched: 9  Changed: 9  Warnings: 0
mysql> EXPLAIN UPDATE Posts SET DeleteAt = 1637998911686, UpdateAt = 1637998911686, Props = JSON_SET(Props, '$.deleteBy', 'buqskqrwmjnhfuqskqrwmjn4ca') Where Id = 'q38uaydtpink5f4wkmcsn8h47o' OR RootId = 'q38uaydtpink5f4wkmcsn8h47o' ORDER BY Id\G
*************************** 1. row ***************************
           id: 1
  select_type: UPDATE
        table: Posts
   partitions: NULL
         type: index_merge
possible_keys: PRIMARY,idx_posts_root_id_delete_at
          key: idx_posts_root_id_delete_at,PRIMARY
      key_len: 107,106
          ref: NULL
         rows: 9
     filtered: 100.00
        Extra: Using sort_union(idx_posts_root_id_delete_at,PRIMARY); Using where; Using filesort
1 row in set, 1 warning (0.00 sec)
```

Postgres uses Bitmap Heap scan which does
a Bitmap OR of the index tuples and _then_
fetches the rows from the heap. This is a
much better and sophisticated way. Sadly, MySQL
will fetch the rows from the indexes first,
and then do an OR, which is why index_merge_intersection
is so bad.

See: https://developers.mattermost.com/blog/mysql-index-merge/
for more info.

```release-note
NONE
```
2021-12-20 13:55:03 +05:30
Olayiwola Odunsi
08dc3a1cdf [GH-19105] - Add helper function to handle columns on reserved names (#19107)
Automatic Merge
2021-12-17 17:40:31 +02:00
Ibrahim Serdar Acikgoz
ca02fabb91 allow upsert for duplicate key 2021-12-17 11:39:25 +03:00
Ujjwal Sharma
1fc8a2ea20 [MM-39640] Migrate from gorp to sqlx in store/sqlstore/role_store.go (#19022)
Automatic Merge
2021-12-15 17:40:31 +02:00
Yair Facio
3b3ab701b1 [MM-39231] Migrate license store from gorp to sqlx in store/sqlstore/license_store.go (#19146)
Automatic Merge
2021-12-12 08:10:31 +02:00
Yair Facio
62d4d8166d [MM-39636] Migrate from gorp to sqlx in store/sqlstore/retention_policy_store.go (#18994)
* Migrate Save from gorp to sqlx

* Migrate checkTeamsExist from gorp to sqlx

* Migrate checkChannelsExist from gorp to sqlx

* Migrate Patch from gorp to sqlx

* Migrate buildGetPoliciesQuery from gorp to sqlx

* Migrate Get from gorp to sqlx

* Change buildGetPolicyQuery return values

* Migrate GetAll from gorp to sqlx

* Migrate GetCount from gorp to sqlx

* Migrate Delete from gorp to sqlx

* Migrate GetChannels from gorp to sqlx

* Migrate GetChannelsCount from gorp to sqlx

* Migrate AddChannels from gorp to sqlx

* Migrate RemoveChannels from gorp to sqlx

* Migrate GetTeams from gorp to sqlx

* Migrate GetTeamsCount from gorp to sqlx

* Migrate AddTeams from gorp to sqlx

* Migrate RemoveTeams from gorp to sqlx

* Migrate DeleteOrphanedRows from gorp to sqlx

* Migrate GetTeamPoliciesForUser from gorp to sqlx

* Migrate GetTeamPoliciesCountForUser from gorp to sqlx

* Migrate GetChannelPoliciesForUser from gorp to sqlx

* Migrate GetChannelPoliciesCountForUser from gorp to sqlx

* Migrate Delete from gorp to sqlx

* Add mapper tag function before saving a record

Summary:
Since there is a db tag in this model for the ID column,
I set a mapper in this transaction to lowercase
all mapping columns before saving the record.

* Use quoted identifiers when selecting Id

* Address PR comments, replace variable declarations for their short hand syntax

* Enhance subquery implementation

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-12-10 14:57:24 +05:30
Yair Facio
fa38202d98 [MM-39636] Migrate from gorp to sqlx in store/sqlstore/product_notices_store.go (#19012)
* Migrate from gorp to sqlx in ProductNoticesStore

* Address PR comments

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-12-10 14:48:46 +05:30
Christopher Speller
5ec78546e2 MM-38150 Adding playbooks permissions (#19096)
* Add playbooks related permissions.

* Add RolesGrantPermission to pluginapi

* Fixing scopes.

* New defaults.

* Fix defaults

* Fix tests.

* Fix migration.

* More test and migration fixes.

* Need to add everything to system admin too.

* Move to 63

* Feedback fixes.

* Fix system manager editing playbook permissions.
2021-12-07 09:43:33 -08:00
Kyriakos Z
36c8d1d1a0 MM-36862: removes participant from thread (#18795)
* MM-36862: removes participant from thread

Removing a participant upon last reply deleted from thread didn't work
reliably, a suspect on this is the replica lag, since we are first
deleting the post and then counting non-deleted posts of the participant
to decide on whether to delete or not.

The findings that led to this conclusion is that the reply count gets
updated but the participant is not removed (participant removal depends
on the number of replies this participant has in the thread.)

This commit fixes that by removing first the participant and then
deleting the post.
So we delete the participant if they have 1 post in that thread, and
then we delete the post, so now they have no posts in the thread.

* Makes deleting posts transactional

This commit makes deleting a post transactional and also tries to fix
permanent deletion of posts.

Currently when we permanently delete all posts by a user we don't update
the threads reply count nor the participant's array. This commit tries
to fix that.

* Adds comments on deleting posts

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-12-06 12:01:04 +02:00
Agniva De Sarker
6a7067e4b6 Clarify comment on golang-migrate connection (#19104)
The old comment wasn't exactly clear on
why is it needed to spawn a new connection.

```release-note
NONE
```
2021-12-03 14:15:43 +01:00
Ben Cooke
27dacb82ce [MM-38239 & MM-39788] Recent files causing crash (#18942)
* wip

* adding tests for new endpoint

* tool updates

* new function for getting postsByIds

* fixing test

* adding limit of 1000 to post query

* fixing PR comments

* fixing permission logic

Co-authored-by: Collin <collineng@gmail.com>
Co-authored-by: Collin Eng <eng.engineereng@gmail.com>
Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MacBook-Pro.local>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MBP.ht.home>
2021-11-26 11:51:32 -05:00
Carlos Tadeu Panato Junior
44d324a45f prepera db upgrade to 6.3 (#19086) 2021-11-26 16:51:25 +01:00
Carlos Tadeu Panato Junior
810edf34a1 upgrade db to 6.2.0 (#19085) 2021-11-26 15:50:09 +01:00
Ashish Bhate
8440a754b4 [MM-37013] Better post filtering (#19013)
Summary:
- Skip searching for deleted posts.

Ticket:
- Part of https://mattermost.atlassian.net/browse/MM-37013
2021-11-23 21:34:29 +05:30
Alex Boutin
3710aae7a1 MM-39635: Migrate gorp to sqlx #18873 (#18945)
Automatic Merge
2021-11-23 07:05:13 +01:00
Ernest Nguyen
47de1f37e6 MM-39632: Migrate from using gorp to sqlx (#18949)
Automatic Merge
2021-11-22 17:05:13 +01:00
Alex Boutin
478b3f7108 MM-39634: Migrated gorp to sqlx (#18951)
* MM-39634: Migrated gorp to sqlx

* MM-39634: Removed redundant limit on get since only one value is returned

* MM-39485: Fixed returned errors + goimports

Co-authored-by: Alex <alex@rumandcode.io>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-11-22 20:58:50 +05:30
Ashish Bhate
0da249c651 [MM-37013] Async job to fix CRT channel unreads (#18340)
Summary
The addition of the TotalMsgCountRoot and MsgCountRoot columns to support CRT caused several issues with previously read threads and channels being marked as unread. Previously we attempted to fix this purely in a SQL migration [MM-35345][MM-35494] fixes for incorrect mentions and unreads for threads and channels #17803 but that turned out to be too heavy and it was decided to break up some of the fixes into async jobs.
This PR implements an async job to mark channels as read if there are no user posts since the last time the user viewed the channel. 

Ticket Link
https://mattermost.atlassian.net/browse/MM-37013
2021-11-18 15:31:18 +05:30
Agniva De Sarker
12dc171a60 MM-39341: Sentry crash: nil dereference in *User.ClearNonProfileFields (#18966)
In some cases, an invalid participant id like an empty string
might creep into the database. It's not exactly clear
how can this happen, but if it does, then it breaks the logic
of assuming that the users slice will contain all users
in the participants slice.

To prevent this, we check if a match was found before
adding it in the slice.

https://community-daily.mattermost.com/boards/workspace/zyoahc9uapdn3xdptac6jb69ic/285b80a3-257d-41f6-8cf4-ed80ca9d92e5/495cdb4d-c13a-4992-8eb9-80cfee2819a4/7sixm4t7c6rsr3d8ydxbtfgy9gr

```release-note
NONE
```
2021-11-17 20:49:40 +05:30
Penthaa Patel
397edef1d8 [MM-39637] - Migrate from gorp to sqlx in store/sqlstore/shared_channel_store.go (#18898)
Automatic Merge
2021-11-16 05:40:13 +01:00
Ujjwal Sharma
627d2b9d6c [MM-39628] Migrate from gorp to sqlx in store/sqlstore/scheme_store.go (#18895)
Automatic Merge
2021-11-15 17:40:13 +01:00
Cesar Bretana
2153dc4d6d [MM-39641] Migrate Webhook store to sqlx (#18896)
* Migrated to sqlx INSERT + UPDATE incoming_webhooks

* Finish migrating IncomingWebhook to sqlx

* wip: outgoing webhooks

* Fix sql syntax error for incoming webhooks

* Add missing fields to insert incoming webhooks query

* Migrate outgoing_webhooks store to sqlx

* Migrate incoming_webhooks analytics count to sqlx

* Migrate outgoing_webhooks analytics count to sqlx

* Fix lint goimports alert

* Migrate unmigrated gorp methods

* Add missing fields to update incoming webhooks sql + remove unnecessary guards

* Address comments from review
2021-11-15 21:13:14 +05:30
Penthaa Patel
25b727d197 [MM-39638] - Migrate from gorp to sqlx in store/sqlstore/status_store.go (#18897)
* migrate from gorp to sqlx

Signed-off-by: Penthaa Patel <penthaapatel@gmail.com>

* fixes

Signed-off-by: Penthaa Patel <penthaapatel@gmail.com>

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-11-15 21:12:30 +05:30
Yair Facio
e1eb0a0cf3 [MM-39643] Migrate from gorp to sqlx in store/sqlstore/system_store.go (#18893)
* Migrate from gorp to sqlx in SystemStore

* Add BeginXWithIsolation method to *sqlxDBWrapper

* Address PR comments
2021-11-15 21:03:55 +05:30