From e0ee73ef9963ab398bcc6011795ad23e8e003147 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 31 Jan 2018 08:26:40 -0600 Subject: ABC-79: Optimize channel autocomplete query (#8163) * optimize channel autocomplete query * move to new autocomplete endpoint --- store/storetest/channel_store.go | 197 +++++++++++++++++++-------------------- 1 file changed, 95 insertions(+), 102 deletions(-) (limited to 'store/storetest/channel_store.go') diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go index 12781bdad..121b40a01 100644 --- a/store/storetest/channel_store.go +++ b/store/storetest/channel_store.go @@ -1940,116 +1940,109 @@ func testChannelStoreSearchInTeam(t *testing.T, ss store.Store) { o11.Type = model.CHANNEL_OPEN store.Must(ss.Channel().Save(&o11, -1)) - if result := <-ss.Channel().SearchInTeam(o1.TeamId, "ChannelA"); result.Err != nil { - t.Fatal(result.Err) - } else { - channels := result.Data.(*model.ChannelList) - if len(*channels) != 2 { - t.Fatal("wrong length") - } - } - - if result := <-ss.Channel().SearchInTeam(o1.TeamId, ""); result.Err != nil { - t.Fatal(result.Err) - } else { - channels := result.Data.(*model.ChannelList) - if len(*channels) == 0 { - t.Fatal("should not be empty") - } - } - - if result := <-ss.Channel().SearchInTeam(o1.TeamId, "blargh"); result.Err != nil { - t.Fatal(result.Err) - } else { - channels := result.Data.(*model.ChannelList) - if len(*channels) != 0 { - t.Fatal("should be empty") - } - } - - if result := <-ss.Channel().SearchInTeam(o1.TeamId, "off-"); result.Err != nil { - t.Fatal(result.Err) - } else { - channels := result.Data.(*model.ChannelList) - if len(*channels) != 2 { - t.Fatal("should return 2 channels, not including private channel") - } - - if (*channels)[0].Name != o7.Name { - t.Fatal("wrong channel returned") - } - - if (*channels)[1].Name != o6.Name { - t.Fatal("wrong channel returned") - } - } - - if result := <-ss.Channel().SearchInTeam(o1.TeamId, "off-topic"); result.Err != nil { - t.Fatal(result.Err) - } else { - channels := result.Data.(*model.ChannelList) - if len(*channels) != 1 { - t.Fatal("should return 1 channel") - } - - if (*channels)[0].Name != o6.Name { - t.Fatal("wrong channel returned") - } - } + for name, search := range map[string]func(teamId string, term string) store.StoreChannel{ + "AutocompleteInTeam": ss.Channel().AutocompleteInTeam, + "SearchInTeam": ss.Channel().SearchInTeam, + } { + t.Run(name, func(t *testing.T) { + if result := <-search(o1.TeamId, "ChannelA"); result.Err != nil { + t.Fatal(result.Err) + } else { + channels := result.Data.(*model.ChannelList) + if len(*channels) != 2 { + t.Fatal("wrong length") + } + } - /* - // Disabling this check as it will fail on PostgreSQL as we have "liberalised" channel matching to deal with - // Full-Text Stemming Limitations. - if result := <-ss.Channel().SearchMore(m1. - if result := <-ss.Channel().SearchInTeam(o1.TeamId, "off-topics"); result.Err != nil { - t.Fatal(result.Err) - } else { - channels := result.Data.(*model.ChannelList) - if len(*channels) != 0 { - t.Fatal("should be empty") + if result := <-search(o1.TeamId, ""); result.Err != nil { + t.Fatal(result.Err) + } else { + channels := result.Data.(*model.ChannelList) + if len(*channels) == 0 { + t.Fatal("should not be empty") + } } - } - */ - if result := <-ss.Channel().SearchInTeam(o1.TeamId, "town square"); result.Err != nil { - t.Fatal(result.Err) - } else { - channels := result.Data.(*model.ChannelList) - if len(*channels) != 1 { - t.Fatal("should return 1 channel") - } + if result := <-search(o1.TeamId, "blargh"); result.Err != nil { + t.Fatal(result.Err) + } else { + channels := result.Data.(*model.ChannelList) + if len(*channels) != 0 { + t.Fatal("should be empty") + } + } - if (*channels)[0].Name != o9.Name { - t.Fatal("wrong channel returned") - } - } + if result := <-search(o1.TeamId, "off-"); result.Err != nil { + t.Fatal(result.Err) + } else { + channels := result.Data.(*model.ChannelList) + if len(*channels) != 2 { + t.Fatal("should return 2 channels, not including private channel") + } + + if (*channels)[0].Name != o7.Name { + t.Fatal("wrong channel returned") + } + + if (*channels)[1].Name != o6.Name { + t.Fatal("wrong channel returned") + } + } - if result := <-ss.Channel().SearchInTeam(o1.TeamId, "the"); result.Err != nil { - t.Fatal(result.Err) - } else { - channels := result.Data.(*model.ChannelList) - t.Log(channels.ToJson()) - if len(*channels) != 1 { - t.Fatal("should return 1 channel") - } + if result := <-search(o1.TeamId, "off-topic"); result.Err != nil { + t.Fatal(result.Err) + } else { + channels := result.Data.(*model.ChannelList) + if len(*channels) != 1 { + t.Fatal("should return 1 channel") + } + + if (*channels)[0].Name != o6.Name { + t.Fatal("wrong channel returned") + } + } - if (*channels)[0].Name != o10.Name { - t.Fatal("wrong channel returned") - } - } + if result := <-search(o1.TeamId, "town square"); result.Err != nil { + t.Fatal(result.Err) + } else { + channels := result.Data.(*model.ChannelList) + if len(*channels) != 1 { + t.Fatal("should return 1 channel") + } + + if (*channels)[0].Name != o9.Name { + t.Fatal("wrong channel returned") + } + } - if result := <-ss.Channel().SearchInTeam(o1.TeamId, "Mobile"); result.Err != nil { - t.Fatal(result.Err) - } else { - channels := result.Data.(*model.ChannelList) - t.Log(channels.ToJson()) - if len(*channels) != 1 { - t.Fatal("should return 1 channel") - } + if result := <-search(o1.TeamId, "the"); result.Err != nil { + t.Fatal(result.Err) + } else { + channels := result.Data.(*model.ChannelList) + t.Log(channels.ToJson()) + if len(*channels) != 1 { + t.Fatal("should return 1 channel") + } + + if (*channels)[0].Name != o10.Name { + t.Fatal("wrong channel returned") + } + } - if (*channels)[0].Name != o11.Name { - t.Fatal("wrong channel returned") - } + if result := <-search(o1.TeamId, "Mobile"); result.Err != nil { + t.Fatal(result.Err) + } else { + channels := result.Data.(*model.ChannelList) + t.Log(channels.ToJson()) + if len(*channels) != 1 { + t.Fatal("should return 1 channel") + } + + if (*channels)[0].Name != o11.Name { + t.Fatal("wrong channel returned") + } + } + }) } } -- cgit v1.2.3-1-g7c22