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

1164 Коммитов

Автор SHA1 Сообщение Дата
Agniva De Sarker
5f4199db4f Revert "Optimize TotalUnreadMentions (#18789)" (#18889)
This reverts commit ec56cac42d.
2021-10-29 14:54:11 +05:30
Agniva De Sarker
ec56cac42d Optimize TotalUnreadMentions (#18789)
* Optimize TotalUnreadMentions

We avoid joining with the Threads table entirely
as ChannelId is available from Posts table directly.

Also we replace left joins by inner joins.

https://community-daily.mattermost.com/boards/workspace/zyoahc9uapdn3xdptac6jb69ic/285b80a3-257d-41f6-8cf4-ed80ca9d92e5/495cdb4d-c13a-4992-8eb9-80cfee2819a4?c=c9aa17f3-b918-4a78-86aa-01562e418634

Old plan

```
 Finalize Aggregate  (cost=30869.29..30869.30 rows=1 width=32) (actual time=27.216..31.674 rows=1 loops=1)
   ->  Gather  (cost=30869.18..30869.29 rows=1 width=32) (actual time=27.089..31.665 rows=2 loops=1)
         Workers Planned: 1
         Workers Launched: 1
         ->  Partial Aggregate  (cost=29869.18..29869.19 rows=1 width=32) (actual time=18.442..18.445 rows=1 loops=2)
               ->  Nested Loop  (cost=1881.68..29869.11 rows=25 width=8) (actual time=2.052..18.417 rows=72 loops=2)
                     ->  Hash Join  (cost=1881.12..29771.45 rows=25 width=62) (actual time=2.028..17.744 rows=72 loops=2)
                           Hash Cond: ((threads.channelid)::text = (channels.id)::text)
                           ->  Nested Loop  (cost=0.84..27883.40 rows=2963 width=89) (actual time=0.220..15.849 rows=163 loops=2)
                                 ->  Parallel Index Scan using threadmemberships_pkey on threadmemberships  (cost=0.41..7423.65 rows=2963 width=35) (actual time=0.031..3.937 rows=2504 loops=2)
                                       Index Cond: ((userid)::text = 'tc3p1yqw67d8idcp3g98awexqe'::text)
                                       Filter: following
                                 ->  Index Scan using threads_pkey on threads  (cost=0.42..6.91 rows=1 width=54) (actual time=0.004..0.004 rows=0 loops=5007)
                                       Index Cond: ((postid)::text = (threadmemberships.postid)::text)
                           ->  Hash  (cost=1866.60..1866.60 rows=1094 width=27) (actual time=1.763..1.764 rows=1002 loops=2)
                                 Buckets: 2048  Batches: 1  Memory Usage: 74kB
                                 ->  Index Scan using idx_channels_team_id_type on channels  (cost=0.42..1866.60 rows=1094 width=27) (actual time=0.022..1.493 rows=1002 loops=2)
                                       Index Cond: ((teamid)::text = '8ywxyw9ocp8smxrmjzrkqhrdwe'::text)
                     ->  Index Scan using posts_pkey on posts  (cost=0.56..3.91 rows=1 width=27) (actual time=0.009..0.009 rows=1 loops=145)
                           Index Cond: ((id)::text = (threads.postid)::text)
                           Filter: (deleteat = 0)
 Planning Time: 2.415 ms
 Execution Time: 31.798 ms
```

New plan

```
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Finalize Aggregate  (cost=34717.01..34717.02 rows=1 width=32) (actual time=42.375..48.143 rows=1 loops=1)
   ->  Gather  (cost=34716.89..34717.00 rows=1 width=32) (actual time=42.249..48.117 rows=2 loops=1)
         Workers Planned: 1
         Workers Launched: 1
         ->  Partial Aggregate  (cost=33716.89..33716.90 rows=1 width=32) (actual time=30.960..30.962 rows=1 loops=2)
               ->  Hash Join  (cost=1881.25..33716.83 rows=25 width=8) (actual time=2.438..30.780 rows=1058 loops=2)
                     Hash Cond: ((posts.channelid)::text = (channels.id)::text)
                     ->  Nested Loop  (cost=0.98..31828.77 rows=2963 width=35) (actual time=0.091..27.374 rows=2504 loops=2)
                           ->  Parallel Index Scan using threadmemberships_pkey on threadmemberships  (cost=0.41..6815.65 rows=2963 width=35) (actual time=0.034..4.674 rows=2504 loops=2)
                                 Index Cond: ((userid)::text = 'tc3p1yqw67d8idcp3g98awexqe'::text)
                                 Filter: following
                           ->  Index Scan using posts_pkey on posts  (cost=0.56..8.44 rows=1 width=54) (actual time=0.008..0.008 rows=1 loops=5007)
                                 Index Cond: ((id)::text = (threadmemberships.postid)::text)
                                 Filter: (deleteat = 0)
                     ->  Hash  (cost=1866.60..1866.60 rows=1094 width=27) (actual time=2.289..2.289 rows=1002 loops=2)
                           Buckets: 2048  Batches: 1  Memory Usage: 74kB
                           ->  Index Scan using idx_channels_team_id_type on channels  (cost=0.42..1866.60 rows=1094 width=27) (actual time=0.028..1.927 rows=1002 loops=2)
                                 Index Cond: ((teamid)::text = '8ywxyw9ocp8smxrmjzrkqhrdwe'::text)
```

```release-note
NONE
```

* Bring back coalesce

```release-note
NONE
```
2021-10-29 09:07:10 +05:30
Saul Pinales
b877e2a95e Migrate from gorp to sqlx in store/sqlstore/group_store.go (#18543)
Automatic Merge
2021-10-28 20:25:26 +02:00
Agniva De Sarker
685b311401 ThreadStore: Remove quadratic complexity for participants population (#18755)
* ThreadStore: Remove quadratic complexity for participants population

While populating the participants, we would traverse the global list
twice to get the users for that thread. For threads with large number
of users, this can take considerable time. We replace that with a map
to change it to O(n).

While here, we improve memory usage of this code by pre-allocating
slices and maps. And also add some comments to help readers.

https://community-daily.mattermost.com/boards/workspace/zyoahc9uapdn3xdptac6jb69ic/285b80a3-257d-41f6-8cf4-ed80ca9d92e5/495cdb4d-c13a-4992-8eb9-80cfee2819a4?c=c9aa17f3-b918-4a78-86aa-01562e418634

```release-note
NONE
```

* Apply in post store as well

```release-note
NONE
```

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-10-28 09:57:54 +05:30
Syerikjan Kh
1091710592 migrate from gorp to sqlx for Preference store (#18742)
Automatic Merge
2021-10-26 16:55:27 +02:00
Ashish Bhate
097d32f409 MM-38445: Set isFollowing to false only when explicitly unfollowed (#18740)
Summary
Set post.IsFollowing to false only if the post is explicitly unfollowed. Otherwise leave it as nil.

Ticket Link
https://mattermost.atlassian.net/browse/MM-38445
2021-10-26 18:50:02 +05:30
Agniva De Sarker
c91ab6267a Revert "Optimize TotalUnreadThreads (#18788)" (#18845)
This reverts commit 971af6935c.
2021-10-26 14:02:03 +05:30
Agniva De Sarker
e24f22745e [MM-18946] [MM-26721] [MM-6842] Cross team search+private channel autocomplete (#18468)
* Show private channels in autocomplete

This is supported in all Engines:
MySQL, Postgres, Bleve, Elasticsearch.

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

```release-note
Private channels will now appear in channel autocomplete.
If you are using Bleve or ElasticSearch, you will have to reindex
the channels again to populate them with the new attributes.
```

A large chunk of this work has been based on the earlier
effort at https://github.com/mattermost/mattermost-server/pull/17804.

Full credit goes to https://github.com/arvinDarmawan.

* Add comment

```release-note
NONE
```

* Adding more tests

```release-note
NONE
```

* fix more tests

```release-note
NONE
```

* tmp

```release-note
NONE
```

* more fixes

```release-note
NONE
```

* add tests

```release-note
NONE
```

* Add review comments from previous PR

```release-note
NONE
```

* Add API to return all channels from all team

```release-note
NONE
```

* Added support for bleve and ES

```release-note
NONE
```

* Streaming response for GetAllChannels

```release-note
NONE
```

* Fix tests

```release-note
NONE
```

* Trigger CI
```release-note
NONE
```

* fix tests

```release-note
NONE
```

* Addressing review comments

```release-note
NONE
```

* Fix lint

```release-note
NONE
```

* Removing flaky test

```release-note
NONE
```

* Address comments

```release-note
NONE
```

* Trigger CI
```release-note
NONE
```

* Added /users/<userid>/channel_members endpoint

```release-note
NONE
```

* Minor edit

```release-note
NONE
```

* Improve embedding

```release-note
NONE
```

* Fix lint error

```release-note
NONE
```

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-10-26 11:30:59 +05:30
Agniva De Sarker
971af6935c Optimize TotalUnreadThreads (#18788)
We remove the left joins with inner joins and also
remove the coalesce on posts.DeleteAt which improves
the join plan from a nested loop to a hash join,
and also allows the DeleteAt to be used as part of the
index filter.

Old plan

```
 Aggregate  (cost=666288.49..666288.50 rows=1 width=8) (actual time=5114.328..5119.991 rows=1 loops=1)
   ->  Gather  (cost=2880.69..666288.27 rows=87 width=8) (actual time=614.214..5119.575 rows=533 loops=1)
         Workers Planned: 2
         Workers Launched: 2
         ->  Nested Loop  (cost=1880.69..665279.57 rows=36 width=8) (actual time=607.821..5099.078 rows=178 loops=3)
               ->  Hash Join  (cost=1880.28..664932.93 rows=229 width=16) (actual time=224.374..1494.698 rows=1866781 loops=3)
                     Hash Cond: ((posts.channelid)::text = (channels.id)::text)
                     ->  Parallel Seq Scan on posts  (cost=0.00..662980.29 rows=27568 width=43) (actual time=201.053..1013.362 rows=4410819 loops=3)
                           Filter: (COALESCE(deleteat, '0'::bigint) = 0)
                     ->  Hash  (cost=1866.60..1866.60 rows=1094 width=27) (actual time=1.486..1.486 rows=1002 loops=3)
                           Buckets: 2048  Batches: 1  Memory Usage: 74kB
                           ->  Index Scan using idx_channels_team_id_type on channels  (cost=0.42..1866.60 rows=1094 width=27) (actual time=0.028..1.331 rows=1002 loops=3)
                                 Index Cond: ((teamid)::text = '8ywxyw9ocp8smxrmjzrkqhrdwe'::text)
               ->  Index Scan using threadmemberships_pkey on threadmemberships  (cost=0.41..1.50 rows=1 width=35) (actual time=0.002..0.002 rows=0 loops=5600344)
                     Index Cond: (((postid)::text = (posts.rootid)::text) AND ((userid)::text = 'tc3p1yqw67d8idcp3g98awexqe'::text))
                     Filter: (following AND (posts.createat > lastviewed))
                     Rows Removed by Filter: 0
 Planning Time: 2.005 ms
 JIT:
   Functions: 59
   Options: Inlining true, Optimization true, Expressions true, Deforming true
   Timing: Generation 9.905 ms, Inlining 122.509 ms, Optimization 293.764 ms, Emission 186.064 ms, Total 612.241 ms
 Execution Time: 5125.739 ms
```

New plan

```
 Aggregate  (cost=683129.17..683129.18 rows=1 width=8) (actual time=1650.746..1656.455 rows=1 loops=1)
   ->  Gather  (cost=3766.65..683085.55 rows=17450 width=27) (actual time=641.073..1656.086 rows=533 loops=1)
         Workers Planned: 2
         Workers Launched: 2
         ->  Hash Join  (cost=2766.65..680340.55 rows=7271 width=27) (actual time=617.096..1635.203 rows=178 loops=3)
               Hash Cond: ((posts.rootid)::text = (threadmemberships.postid)::text)
               Join Filter: (posts.createat > threadmemberships.lastviewed)
               Rows Removed by Join Filter: 6
               ->  Hash Join  (cost=1880.28..679334.08 rows=45742 width=16) (actual time=15.196..1242.832 rows=1866781 loops=3)
                     Hash Cond: ((posts.channelid)::text = (channels.id)::text)
                     ->  Parallel Seq Scan on posts  (cost=0.00..662980.29 rows=5513543 width=43) (actual time=0.028..775.118 rows=4410819 loops=3)
                           Filter: (deleteat = 0)
                     ->  Hash  (cost=1866.60..1866.60 rows=1094 width=27) (actual time=1.572..1.573 rows=1002 loops=3)
                           Buckets: 2048  Batches: 1  Memory Usage: 74kB
                           ->  Index Scan using idx_channels_team_id_type on channels  (cost=0.42..1866.60 rows=1094 width=27) (actual time=0.025..1.372 rows=1002 loops=3)
                                 Index Cond: ((teamid)::text = '8ywxyw9ocp8smxrmjzrkqhrdwe'::text)
               ->  Hash  (cost=823.41..823.41 rows=5037 width=35) (actual time=256.240..256.241 rows=5007 loops=3)
                     Buckets: 8192  Batches: 1  Memory Usage: 417kB
                     ->  Bitmap Heap Scan on threadmemberships  (cost=159.45..823.41 rows=5037 width=35) (actual time=253.011..255.255 rows=5007 loops=3)
                           Recheck Cond: ((userid)::text = 'tc3p1yqw67d8idcp3g98awexqe'::text)
                           Filter: following
                           Heap Blocks: exact=601
                           ->  Bitmap Index Scan on idx_thread_memberships_user_id  (cost=0.00..158.19 rows=5037 width=0) (actual time=0.627..0.627 rows=5037 loops=3)
                                 Index Cond: ((userid)::text = 'tc3p1yqw67d8idcp3g98awexqe'::text)
 Planning Time: 1.952 ms
 JIT:
   Functions: 83
   Options: Inlining true, Optimization true, Expressions true, Deforming true
   Timing: Generation 10.148 ms, Inlining 115.819 ms, Optimization 395.923 ms, Emission 244.130 ms, Total 766.021 ms
 Execution Time: 1661.791 ms
```

No special test has been done on MySQL since these are pretty
basic optimizations and should apply to both equally.

https://community-daily.mattermost.com/boards/workspace/zyoahc9uapdn3xdptac6jb69ic/285b80a3-257d-41f6-8cf4-ed80ca9d92e5/495cdb4d-c13a-4992-8eb9-80cfee2819a4?c=c9aa17f3-b918-4a78-86aa-01562e418634

```release-note
NONE
```
2021-10-26 08:56:38 +05:30
Joremy Sh
ff4df47cb1 Migrated from gorp to sqlx in store/sqlstore/plugin_store.go (#18729)
* Migrated from gorp to sqlx in store/sqlstore/plugin_store.go

* fixed lint

* updated QueryRowx and keys type

* used QueryRowX

* Fix query

Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
2021-10-21 09:57:49 +05:30
Shobhit Gupta
e36d0576a6 Migrate from gorp to sqlx in store/sqlstore/command_store.go (#18728) 2021-10-21 09:57:33 +05:30
Anusha Bhat
f5bcb12aab [MM-39232] Migrate from gorp to sqlx in store/sqlstore/reaction_store.go (#18657)
* [MM-39232] Migrate from gorp to sqlx in store/sqlstore/reaction_store.go

* Fix failing mysql tests

* Fix failing postgres specs

* Use struct instead of params
2021-10-21 09:55:49 +05:30
Archit Mathur
8ac9a3a5b6 [MM-39157] Thread participant removal with just one query using DB's JSON functions (#18725)
* feat: removes thread participant with just one query using DB's native JSON functions

* fix: corrects syntax post test failure
2021-10-19 14:07:17 -04:00
Agniva De Sarker
acd08f0a48 Fix migration scripts (#18756)
* Fix migration scripts

Set the DB schema version in DB prior to running migration

https://community-daily.mattermost.com/boards/workspace/zyoahc9uapdn3xdptac6jb69ic/285b80a3-257d-41f6-8cf4-ed80ca9d92e5/495cdb4d-c13a-4992-8eb9-80cfee2819a4?c=c2525dbb-23eb-4fe7-8fb4-e9a5f503dc8c

```release-note
NONE
```

* Revert schema to 6.0.0 and update CI scripts

* Fix typo

* Add missing default

* Fix extra comma

Co-authored-by: Claudio Costa <cstcld91@gmail.com>
2021-10-19 19:56:09 +05:30
Penthaa Patel
078fdd8422 [MM-39229] - Migrate from gorp to sqlx in store/sqlstore/link_metadata_store.go (#18702)
* migrate from gorp to sqlx

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

* fix INSERT query

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

* fixes

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

* fix Get function

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

* fixes - serialize metadata_Data to JSON

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

* fixes - wrap metadataBytes with string

Signed-off-by: Penthaa Patel <penthaapatel@gmail.com>
2021-10-19 19:49:45 +05:30
Shobhit Gupta
e12e0df447 Migrate from gorp to sqlx in store/sqlstore/job_store.go (#18518) 2021-10-19 19:29:24 +05:30
Igor German
93f956e478 [GH-18504] Migrate from gorp to sqlx in store/sqlstore/file_info_store.go (#18637)
* Migrate from gorp to sqlx in store/sqlstore/file_info_store.go

Signed-off-by: Igor German <germanenak@gmail.com>

* Use separate structs for FileInfo

Signed-off-by: Igor German <germanenak@gmail.com>

* Fix CR comments

Signed-off-by: Igor German <germanenak@gmail.com>

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-10-19 19:29:10 +05:30
Kyriakos Z
0f16c59b0a MM-36862: should remove user from participants (#18451)
* MM-36862: should remove user from participants

When deleting a reply in a thread we should also delete the participant
from the participants array. This should happen if they have no other
replies in that thread.

This commit fixes that.

* Adds warning logs

* Delete Post: fetches participants only when needed

* Minor refactor

* Remove participant should check for error in count

* Fixes error when binary_parameters=true

* Fixes: removes ArrayToJSON so we can handle the error

* Satisfies the linter

* Better error handling

* Satisfy govet

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-10-15 19:40:09 +03:00
Penthaa Patel
c02cdd842a [MM-38996] - Migrate from gorp to sqlx in store/sqlstore/compliance_store.go (#18633)
* migrate from gorp to sqlx in store/sqlstore/compliance_store.go

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

* fix SQL syntax

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

* fix SQL syntax

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

* fix SQL syntax

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

* fix SQL syntax error

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

* Fixes

```release-note
NONE
```

Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
2021-10-15 20:06:57 +05:30
Agniva De Sarker
99e6039472 Add functionality to cleanup old jobs (#18646)
* Add functionality to cleanup old jobs

Historically, we never cleaned up old jobs from the DB
leading to them being accumulated forever.

This PR introduces functionality to cleanup old jobs
older than a defined threshold.

The functionality is set to false by default and has
to be enabled for it to work.

```release-note
2 new config settings were added.

JobSettings.CleanupOldJobs: This indicates whether to clean up old jobs
from the DB or not. Default is false.

JobSettings.CleanupJobsThresholdHours: This defines the time gap in hours beyond
which older jobs will be removed. This has no effect if the above config
setting is set to false. Default is -1
```

* fix copy pasta

```release-note
NONE
```

* address review comments

```release-note
NONE
```

* Fix lint

```release-note
NONE
```

* Use single config option for everything

```release-note
NONE
```

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-10-15 11:03:54 +05:30
Claudio Costa
9d8214c72a Drop existing default on Users.Timezone prior to column type change (#18669) 2021-10-14 17:18:18 +02:00
Kyriakos Z
4b85f9ee6a MM-36743: adds last_root_post_at in channels table (#18366)
* MM-36743: adds last_root_post_at in channels table

Channel recency for CRT users should not count replies,
this commit solves that issue by adding a new column to the channels
table: LastRootPostAt.
With that new info CRT users can have recent channels to work as
expected.

* Adds the 'LastRootPostAt' to the SQL scripts

* Fixes tests

* Adds LastRootPostAt migration to v6.1

* Fixes index

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-10-13 15:20:44 -04:00
Agniva De Sarker
e2c87ef950 Display tableName and columnName for jsonb schema failures (#18672)
These are incredibly helpful during failures and should be there.

```release-note
NONE
```
2021-10-13 20:30:35 +05:30
Carlos Tadeu Panato Junior
3b81d9f83e db: add db upgrade for 5.39 and upgrade to 6 (#18645) 2021-10-12 09:37:56 +02:00
Archit Mathur
d13b3604ea Cluster Discovery store sqlx migration (#18605)
Automatic Merge
2021-10-07 16:50:03 +02:00
Agniva De Sarker
d9dda9f7c6 Add index on Jobs table (#18244)
From Grafana charts, GetCountbyStatusandType and
GetNewestJobByStatusesAndType were the two top queries.

Overall, a through look into all job methods leads to
the conclusion of 2 indexes - one on CreateAt, another
a compound index of Status+Type. I have just gone ahead
with the compound index for now. Once the job cleaner
is implemented, I want to take a second look to decide
whether to add the second index or not.

Here is the before-after of the queries:

Query 1:
```
explain analyze select count(*) from jobs where status='error' and type='migrations';
                                                         QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=103.42..103.43 rows=1 width=8) (actual time=0.032..0.034 rows=1 loops=1)
   ->  Bitmap Heap Scan on jobs  (cost=4.54..103.42 rows=1 width=0) (actual time=0.027..0.028 rows=0 loops=1)
         Recheck Cond: ((type)::text = 'migrations'::text)
         Filter: ((status)::text = 'error'::text)
         ->  Bitmap Index Scan on idx_jobs_type  (cost=0.00..4.54 rows=34 width=0) (actual time=0.018..0.019 rows=0 loops=1)
               Index Cond: ((type)::text = 'migrations'::text)

explain analyze select count(*) from jobs where status='error' and type='migrations';
                                                         QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------
Aggregate  (cost=8.31..8.32 rows=1 width=8) (actual time=0.079..0.080 rows=1 loops=1)
   ->  Index Only Scan using jobs_multi on jobs  (cost=0.29..8.30 rows=1 width=0) (actual time=0.072..0.073 rows=0 loops=1)
         Index Cond: ((status = 'error'::text) AND (type = 'migrations'::text))
         Heap Fetches: 0

explain analyze select * from jobs where status='error' and type='migrations' order by createat desc limit 1;
```

Query 2:
```
                                                            QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=8.31..8.32 rows=1 width=187) (actual time=0.037..0.039 rows=0 loops=1)
   ->  Sort  (cost=8.31..8.32 rows=1 width=187) (actual time=0.035..0.036 rows=0 loops=1)
         Sort Key: createat DESC
         Sort Method: quicksort  Memory: 25kB
         ->  Index Scan using idx_jobs_type on jobs  (cost=0.29..8.30 rows=1 width=187) (actual time=0.027..0.027 rows=0 loops=1)
               Index Cond: ((type)::text = 'migrations'::text)
               Filter: ((status)::text = 'error'::text)

explain analyze select * from jobs where status='error' and type='migrations' order by createat desc limit 1;
                                                          QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=8.31..8.32 rows=1 width=187) (actual time=0.065..0.067 rows=0 loops=1)
   ->  Sort  (cost=8.31..8.32 rows=1 width=187) (actual time=0.063..0.064 rows=0 loops=1)
         Sort Key: createat DESC
         Sort Method: quicksort  Memory: 25kB
         ->  Index Scan using jobs_multi on jobs  (cost=0.29..8.30 rows=1 width=187) (actual time=0.021..0.022 rows=0 loops=1)
               Index Cond: (((status)::text = 'error'::text) AND ((type)::text = 'migrations'::text))

```

```release-note
NONE
```
2021-10-07 11:55:59 +05:30
Pijus Kamandulis
d639a08064 MM-38624 Migrate ChannelMemberHistoryStore to sqlx (#18496)
Automatic Merge
2021-10-06 19:50:02 +02:00
Saul Pinales
7b9aeca7ff Migrate from gorp to sqlx in store/sqlstore/command_webhook_store.go (#18517)
* Migrate from gorp to sqlx in store/sqlstore/command_webhook_store.go

* fixing small things

change `CreatedAt` to `CreateAt` and change GetReplicaX().Select to GetReplicaX().Get

Co-authored-by: Saul Pinales <saul021002@gmai.com>
2021-10-05 21:22:50 +05:30
Claudio Costa
b724ba6243 Execute update posts query first (#18524) 2021-10-04 15:04:13 +02:00
Claudio Costa
177680f08c [MM-36472] Fix inconsistencies in Roles columns (#18390)
* Fix inconsistencies in Roles columns

* Add new migrations
2021-10-01 15:31:29 +02:00
Daniel Espino García
305e4793c3 Only consider flagged posts that are on channels you are member of (#18380)
* Only consider flagged posts that are on channels you are member of

* Fix and add tests
2021-09-29 17:16:25 -04:00
Daniel Espino García
02a9ef3f82 [MM-38216] Add API endpoint and adapt search to allow multi-team search (#18371)
* Add API endpoint and adapt search to allow multi-team search

* Refactor handler, refactor sql query to use squirrel, rename app and store functions and add tests

* Fix lint

* Fix search engines and remove unneeded comments

* Fix test

* Remove user from channel after test
2021-09-23 14:43:09 +02:00
Agniva De Sarker
688ee34054 MM-38712: Flush logs while exiting from store upgrade (#18438)
Our store upgrade methods used mlog.Critical and then slept
for a second and triggered os.Exit.

First of all, with the new mlog refactor Critical wasn't a standard
log level so it was never to be logged.

And secondly, this completely missed the fact that there already
existed an API method Fatal which did exactly this.

We mark the Critical API as deprecated, and use Fatal for all
occurences.

The choice should be between either to use Error or Fatal.

While here, we also remove the non-standard exit codes which
just confused things further while debugging.

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

```release-note
NONE
```
2021-09-22 20:12:57 +05:30
Doug Lauder
a1b853d1dc MM-38611 getSharedChannels: only return channels user is member of (#18417)
* getSharedChannels: only return channels user is member of
2021-09-20 15:00:47 -04:00
dave
fd597d325a Migrate from gorp to sqlx in store/sqlstore/audit_store.go (#18409) 2021-09-20 18:55:36 +05:30
Kyriakos Z
237e4fd531 MM-37896: thread recency when updating a post (#18363)
When a post is edited we should not update the thread recency
(LastReplyAt).
2021-09-17 09:01:41 -04:00
Agniva De Sarker
0953e3f0cf Migrating Emoji store to use sqlx (#18301)
* Migrating Emoji store to use sqlx

https://community-daily.mattermost.com/boards/workspace/zyoahc9uapdn3xdptac6jb69ic/285b80a3-257d-41f6-8cf4-ed80ca9d92e5/495cdb4d-c13a-4992-8eb9-80cfee2819a4?c=646cee9a-219c-49f3-8e0b-6ec2cff4deba

```release-note
NONE
```

* Incorporate review suggestions

```release-note
NONE
```

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-09-14 13:46:42 +05:30
Agniva De Sarker
17fe158f5e Migrating OAuthStore to sqlx (#18302)
* Migrating OAuthStore to sqlx

https://community-daily.mattermost.com/boards/workspace/zyoahc9uapdn3xdptac6jb69ic/285b80a3-257d-41f6-8cf4-ed80ca9d92e5/495cdb4d-c13a-4992-8eb9-80cfee2819a4?c=71efa7c4-53be-4732-87cc-d53726d2cd53

```release-note
NONE
```

* Fixing some broken tests

```release-note
NONE
```

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-09-13 19:23:58 +05:30
Agniva De Sarker
21a53320d3 Migrating bot store to use sqlx (#18300)
https://community-daily.mattermost.com/boards/workspace/zyoahc9uapdn3xdptac6jb69ic/285b80a3-257d-41f6-8cf4-ed80ca9d92e5/495cdb4d-c13a-4992-8eb9-80cfee2819a4?c=5da060fd-8fbc-449d-8219-c73a9dd0bd7c

```release-note
NONE
```
2021-09-02 17:08:11 +02:00
Claudio Costa
92837fa1ee [MM-22051] Remove To/From JSON (#18070)
* Posts

* Add missing translation

* Fix internal store marshaling

* [MM-22051] Remove To/From JSON (Channels) (#18116)

* Channels

* Channel members

* ChannelSearch

* Channel categories, list, sidebar, stats, view

* Fix conversions

* [MM-22051] Remove To/From JSON (Users) (#18121)

* User related structs

* Fix return

* Team related structures (#18127)

* [MM-22051] Remove To/From JSON (Status, Bot, Reaction, Thread, FileInfo) (#18130)

* Status

* Bot

* Reaction

* Thread

* FileInfo

* Some fixes

* Translations update from Weblate (#18143)

* Translated using Weblate (German)

Currently translated at 100.0% (2309 of 2309 strings)

Translation: mattermost-languages-shipped/mattermost-server
Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/de/

* Translated using Weblate (Turkish)

Currently translated at 100.0% (2309 of 2309 strings)

Translation: mattermost-languages-shipped/mattermost-server
Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/tr/

* Translated using Weblate (Hungarian)

Currently translated at 100.0% (2309 of 2309 strings)

Translation: mattermost-languages-shipped/mattermost-server
Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/hu/

* Update translation files

Updated by "Cleanup translation files" hook in Weblate.

Translation: mattermost-languages-shipped/mattermost-server
Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/

Update translation files

Updated by "Cleanup translation files" hook in Weblate.

Translation: mattermost-languages-shipped/mattermost-server
Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/

Update translation files

Updated by "Cleanup translation files" hook in Weblate.

Translation: mattermost-languages-shipped/mattermost-server
Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/

Update translation files

Updated by "Cleanup translation files" hook in Weblate.

Translation: mattermost-languages-shipped/mattermost-server
Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/

* Translated using Weblate (German)

Currently translated at 100.0% (2301 of 2301 strings)

Translation: mattermost-languages-shipped/mattermost-server
Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/de/

* Translated using Weblate (Turkish)

Currently translated at 100.0% (2301 of 2301 strings)

Translation: mattermost-languages-shipped/mattermost-server
Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/tr/

* Translated using Weblate (Hungarian)

Currently translated at 100.0% (2301 of 2301 strings)

Translation: mattermost-languages-shipped/mattermost-server
Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/hu/

* Translated using Weblate (English (Australia))

Currently translated at 100.0% (2301 of 2301 strings)

Translation: mattermost-languages-shipped/mattermost-server
Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/en_AU/

* Translated using Weblate (Bulgarian)

Currently translated at 100.0% (2301 of 2301 strings)

Translation: mattermost-languages-shipped/mattermost-server
Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/bg/

* Translated using Weblate (Japanese)

Currently translated at 100.0% (2301 of 2301 strings)

Translation: mattermost-languages-shipped/mattermost-server
Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ja/

* Translated using Weblate (Chinese (Simplified))

Currently translated at 100.0% (2301 of 2301 strings)

Translation: mattermost-languages-shipped/mattermost-server
Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/zh_Hans/

Co-authored-by: JtheBAB <srast@bioc.uzh.ch>
Co-authored-by: Kaya Zeren <kayazeren@gmail.com>
Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu>
Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au>
Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com>
Co-authored-by: kaakaa <stooner.hoe@gmail.com>
Co-authored-by: aeomin <lin@aeomin.net>

Co-authored-by: Weblate (bot) <hosted@weblate.org>
Co-authored-by: JtheBAB <srast@bioc.uzh.ch>
Co-authored-by: Kaya Zeren <kayazeren@gmail.com>
Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu>
Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au>
Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com>
Co-authored-by: kaakaa <stooner.hoe@gmail.com>
Co-authored-by: aeomin <lin@aeomin.net>

* [MM-22051] Remove To/From JSON methods from model (#18138)

* Scheme

* Role

* Session

* Config

* Status

* Fix logic

* Emoji

* GuestsInvite

* Group

* Command

* ClusterInfo

* License

* Job

* System

* Plugin

* Command2

* IncomingWebhook

* OutgoingWebhook

* Fix tests

* Update traslation

* Some fixes

* Add missing return

* Simplify

* Make Config.ToJSONFiltered() return []byte

* Make Busy.ToJSON() return []byte

* Include error in log

* Split logic

* [MM-22051] Remove To/From JSON (final) (#18150)

* SwitchRequest

* PluginEventData

* Permalink

* PushNotification

* SuggestCommand

* PluginsResponse

* WebSocketMessage

* RemoteCluster

* SharedChannel

* PluginStatuses

* InitialLoad

* ClusterDiscovery

* ClusterStats

* MfaSecret

* GroupSyncable

* SAML

* WebSocketRequest

* TypingRequest

* SecurityBulletin

* OAuthApp

* IntegrationAction

* DataRetention

* Preference

* FileInfoList

* Compliance

* Preferences

* FileInfoSearchResults

* TermsOfService

* InstallMarketplacePluginRequest

* GitLabUser

* UploadSessions

* Remove unused helpers

* Fix tests

* [MM-23280] Fix linting for ToJSON/FromJSON (#18153)

* SwitchRequest

* PluginEventData

* Permalink

* PushNotification

* SuggestCommand

* PluginsResponse

* WebSocketMessage

* RemoteCluster

* SharedChannel

* PluginStatuses

* InitialLoad

* ClusterDiscovery

* ClusterStats

* MfaSecret

* GroupSyncable

* SAML

* WebSocketRequest

* TypingRequest

* SecurityBulletin

* OAuthApp

* IntegrationAction

* DataRetention

* Preference

* FileInfoList

* Compliance

* Preferences

* FileInfoSearchResults

* TermsOfService

* InstallMarketplacePluginRequest

* GitLabUser

* UploadSessions

* Remove unused helpers

* Fix tests

* Fix linting for ToJSON/FromJSON

* Fix conversions

Co-authored-by: Weblate (bot) <hosted@weblate.org>
Co-authored-by: JtheBAB <srast@bioc.uzh.ch>
Co-authored-by: Kaya Zeren <kayazeren@gmail.com>
Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu>
Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au>
Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com>
Co-authored-by: kaakaa <stooner.hoe@gmail.com>
Co-authored-by: aeomin <lin@aeomin.net>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-09-01 14:43:12 +02:00
Kyriakos Z
bb05e7c412 MM-35017: order and inclusion of participants (#18235)
* MM-35017: order and inclusion of participants

From now on root poster is not considered a thread participant,
only repliers are participants.

Ordering: A second reply to the thread from the same user should place
the user last at the participants list.

* Fixes shadow

* Fixes tests

* Order By CreateAt for participants of old threads

* Removes unnecessary check on root id

* Removes GetParticipantProfilesByIds it's not needed

At first GetParticipantProfilesByIds was created because GetProfileByIds
gets users by order of username.
This was not needed, we can order by user ids in Go.

This commit removes GetParticipantProfilesByIds and replaces it by
GetProfileByIds as it was done before.

* Fixes participants order for pre CRT threads

Older threads (before CRT) are being converted to CRT threads upon
reply.
This commit considers the order of participants to be inserted to
the new thread.

* Adds tests for thread participants

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-08-30 17:13:55 -04:00
Agniva De Sarker
5b8720d539 MM-38132: Improve Auto Responder logic (#18264)
We properly truncate the date part from the createAt time.

The SQL query is improved now to directly return the bool.

Fixed the test to properly test the feature.

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

```release-note
NONE
```
2021-08-30 23:06:45 +05:30
Agniva De Sarker
1f3e2d0c4f Added a sqlXPassThrough layer (#18238)
* Added a sqlXPassThrough layer

This layer embeds the original sqlx object and wraps some
key methods to avoid some boilerplate.

- Add timeout to all methods from the timeout in settings.
- Added trace functionality.
- Added auto-rebind capabilities so that each store method
doesn't need to call rebind every time.
- Added auto-lowering of query string to support NamedExec
for both MySQL and Postgres

All methods are not wrapped as all are likely not to be called
from our code. As and when they are called, support will be added.

```release-note
NONE
```

* fix lint issues

```release-note
NONE
```

* address review comments

```release-note
NONE
```

* incorporate suggestions

```release-note
NONE
```
2021-08-30 10:20:28 +05:30
Carlos Tadeu Panato Junior
6031b163d8 Update MM version/sqlstore to version 6.0.0 (#18247)
Automatic Merge
2021-08-24 16:15:03 +02:00
Agniva De Sarker
7bbcf86531 Update channel member notify props to use native JSON (#18114)
* Update channel member notify props to use native JSON

Created a new store method that patches the notify props field.

https://community-daily.mattermost.com/plugins/focalboard/workspace/zyoahc9uapdn3xdptac6jb69ic?id=285b80a3-257d-41f6-8cf4-ed80ca9d92e5&v=495cdb4d-c13a-4992-8eb9-80cfee2819a4&c=91d08676-4a0e-4f02-8dce-d24d4fc56449

```release-note
NONE
```

* cleanup

```release-note
NONE
```

* forgot to commit

```release-note
NONE
```

* Fix edge case

```release-note
NONE
```

* address review comments

```release-note
NONE
```

* fix incorrect order

```release-note
NONE
```

* Address review comments

```release-note
NONE
```

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-08-23 10:04:30 +05:30
Claudio Costa
c4c1fda128 [MM-36387] Address db performance audit items (#18078) 2021-08-21 08:05:52 +03:00
Agniva De Sarker
b553b50e15 Prepare support for sqlx (#18133)
* Prepare support for sqlx

Just setting up some basic skeleton to start
replacing gorp queries with sqlx.

There is still an issue with efficiently writing
cross-platform named queries, because :FieldName
needs to be :fieldname for Postgres.

The positional params can be rebound depending on
driver name. But named queries can't from my
investigation. Will look into this.

```release-note
NONE
```

* Refactor mapper

```release-note
NONE
```

* Forgot to init slice

```release-note
NONE
```

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-08-20 10:53:34 +02:00
Claudio Costa
74518ea165 Combine alterations on Posts table (#18210)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-08-20 09:56:17 +02:00
Kyriakos Z
a0c5d8feab MM-36234,MM-37030,MM-37031: CRT, desktop thread notifications (#18088)
* CRT: desktop thread notifications

* Fixes go lint

* Adds default for desktop CRT notifications

* Adds email and push notifications for CRT threads

Adds user ids of thread followers with CRT to crtMentions so they will get
notified appropriately.

* Minor change

* Refactor a bit

CRTMentions.addMention had a bug on the return and de-duplication.
This commit fixes duplicate notifications by looking up if the user is to be
notified on CRT on both email and push notifications.

* Minor refactor

* Changes according to review comments

- Fixes adding to followers a user that had explicitly unfollowed a
  thread.
- Simplified send email according to email_threads option
- Send mentions and followers in separate arrays via the websocket
- Fixes push notifications message for push_threads

* Adds a comment on a buggy use case

* Updates comment to correct ticket link

* Fixes when user notifications is set to all

There was a bug where if user had set notifications to all
then they would receive desktop notifications even for non following threads.

A similar bug existed in push notifications, where if a user has set it
to all the threads setting would still be considered.

This commit fixes that by adding users to notificationsForCRT
StringArray when they have the non thread setting to 'all'.

* Fixes notifications to users unfollowing threads

Users which had previously explicitly unfollowed a thread
should not receive notifications about those threads.

* Update store mocks

* Fixes push notifications for CRT

Push notification about replies for CRT users should have a title of
"Reply to Thread".

CRT users with global user setting to 'UserNotifyAll' should not get
notifications for unfollowed threads.

This commit fixes those issues.

* Fixes i18n error

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-08-19 17:28:46 +03:00
Claudio Costa
536895a9ba Bump max allowed file uploads per post (#17948) 2021-08-18 15:50:17 +02:00