* 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>
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
* 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>
* 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>
* [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
* 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>
* 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>
* 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>
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
```
* 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>
* 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
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
```