mattermost/server/channels/store/sqlstore/testpool.go
Ben Schumacher 60fbce7d03
Some checks are pending
API / build (push) Waiting to run
Server CI / Compute Go Version (push) Waiting to run
Server CI / Check mocks (push) Blocked by required conditions
Server CI / Check go mod tidy (push) Blocked by required conditions
Server CI / check-style (push) Blocked by required conditions
Server CI / Check serialization methods for hot structs (push) Blocked by required conditions
Server CI / Vet API (push) Blocked by required conditions
Server CI / Check migration files (push) Blocked by required conditions
Server CI / Generate email templates (push) Blocked by required conditions
Server CI / Check store layers (push) Blocked by required conditions
Server CI / Check mmctl docs (push) Blocked by required conditions
Server CI / Postgres with binary parameters (push) Blocked by required conditions
Server CI / Postgres (push) Blocked by required conditions
Server CI / Postgres (FIPS) (push) Blocked by required conditions
Server CI / Generate Test Coverage (push) Blocked by required conditions
Server CI / Run mmctl tests (push) Blocked by required conditions
Server CI / Run mmctl tests (FIPS) (push) Blocked by required conditions
Server CI / Build mattermost server app (push) Blocked by required conditions
Web App CI / check-lint (push) Waiting to run
Web App CI / check-i18n (push) Blocked by required conditions
Web App CI / check-types (push) Blocked by required conditions
Web App CI / test (platform) (push) Blocked by required conditions
Web App CI / test (mattermost-redux) (push) Blocked by required conditions
Web App CI / test (channels shard 1/4) (push) Blocked by required conditions
Web App CI / test (channels shard 2/4) (push) Blocked by required conditions
Web App CI / test (channels shard 3/4) (push) Blocked by required conditions
Web App CI / test (channels shard 4/4) (push) Blocked by required conditions
Web App CI / upload-coverage (push) Blocked by required conditions
Web App CI / build (push) Blocked by required conditions
[MM-67671] Add CJK Post search support for PostgreSQL (#35260)
Add LIKE-based CJK (Chinese, Japanese, Korean) search support for PostgreSQL, gated behind a `CJKSearch` feature flag.

PostgreSQL's built-in full-text search (`to_tsvector`/`to_tsquery`) does not support CJK languages because it relies on whitespace-based tokenization, which doesn't work for logographic/syllabic scripts that don't use spaces between words. This PR adds a `LIKE`-based fallback for search terms containing CJK characters.

**How it works:** When the `CJKSearch` feature flag is enabled and a search term contains CJK characters (Han, Hiragana, Katakana, or Hangul), the query builder generates `LIKE '%term%'` clauses instead of `to_tsvector @@ to_tsquery` expressions. Case-sensitive `LIKE` is used rather than `ILIKE` since CJK scripts have no letter casing, which also allows potential use of standard B-tree indexes.
2026-02-25 10:18:51 -05:00

115 lines
2.7 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package sqlstore
import (
"sync"
"testing"
"golang.org/x/sync/errgroup"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/v8/channels/store/storetest"
)
// TestPool is used to facilitate the efficient (and safe) use of test stores in parallel tests (e.g. in api4, app, sqlstore).
type TestPool struct {
entries map[string]*TestPoolEntry
mut sync.Mutex
logger mlog.LoggerIFace
}
type TestPoolEntry struct {
Store *SqlStore
Settings *model.SqlSettings
}
func NewTestPool(logger mlog.LoggerIFace, driverName string, poolSize int) (*TestPool, error) {
logger.Info("Creating test store pool", mlog.Int("poolSize", poolSize))
entries := make(map[string]*TestPoolEntry, poolSize)
var mut sync.Mutex
var eg errgroup.Group
for range poolSize {
eg.Go(func() error {
settings := storetest.MakeSqlSettings(driverName)
sqlStore, err := New(*settings, logger, nil, WithFeatureFlags(func() *model.FeatureFlags {
return &model.FeatureFlags{CJKSearch: true}
}))
if err != nil {
return err
}
mut.Lock()
logger.Info("Initializing test store in pool", mlog.String("datasource", *settings.DataSource))
entries[*settings.DataSource] = &TestPoolEntry{
Store: sqlStore,
Settings: settings,
}
mut.Unlock()
return nil
})
}
if err := eg.Wait(); err != nil {
return nil, err
}
return &TestPool{
entries: entries,
logger: logger,
}, nil
}
func (p *TestPool) Get(t testing.TB) *TestPoolEntry {
p.mut.Lock()
defer p.mut.Unlock()
p.logger.Info("Getting from test store pool", mlog.Int("poolSize", len(p.entries)))
var poolEntry *TestPoolEntry
for _, entry := range p.entries {
poolEntry = entry
delete(p.entries, *entry.Settings.DataSource)
break
}
// No more stores available in the pool
if poolEntry == nil {
return nil
}
p.logger.Info("Got store from pool", mlog.String("datasource", *poolEntry.Settings.DataSource), mlog.Int("poolSize", len(p.entries)))
dataSource := *poolEntry.Settings.DataSource
// Return store to pool on test cleanup
t.Cleanup(func() {
p.mut.Lock()
defer p.mut.Unlock()
p.logger.Info("Returning to test store pool", mlog.String("datasource", dataSource), mlog.Int("poolSize", len(p.entries)))
p.entries[dataSource] = poolEntry
})
return poolEntry
}
func (p *TestPool) Close() {
p.mut.Lock()
defer p.mut.Unlock()
var wg sync.WaitGroup
wg.Add(len(p.entries))
for _, entry := range p.entries {
go func() {
defer wg.Done()
entry.Store.Close()
storetest.CleanupSqlSettings(entry.Settings)
}()
}
wg.Wait()
}