MM-13664 Cache external link metadata when populating post metadata (#10128)

* MM-13664 Added LinkMetadata types

* MM-13664 Use LinkMetadata when populating post metadata

* Fix unused import

* Fix index name on SQLite

* Finish adding unit tests

* Address feedback

* Increase max length of URL column to 2048 characters
Этот коммит содержится в:
Harrison Healey
2019-01-28 10:25:08 -05:00
коммит произвёл Carlos Tadeu Panato Junior
родитель 5c76e90a83
Коммит 26684716aa
22 изменённых файлов: 1483 добавлений и 50 удалений

Просмотреть файл

@@ -15,6 +15,7 @@ import (
"sync/atomic"
"time"
"github.com/dyatlov/go-opengraph/opengraph"
"github.com/go-sql-driver/mysql"
"github.com/lib/pq"
"github.com/mattermost/gorp"
@@ -95,6 +96,7 @@ type SqlSupplierOldStores struct {
TermsOfService store.TermsOfServiceStore
group store.GroupStore
UserTermsOfService store.UserTermsOfServiceStore
linkMetadata store.LinkMetadataStore
}
type SqlSupplier struct {
@@ -145,6 +147,7 @@ func NewSqlSupplier(settings model.SqlSettings, metrics einterfaces.MetricsInter
supplier.oldStores.plugin = NewSqlPluginStore(supplier)
supplier.oldStores.TermsOfService = NewSqlTermsOfServiceStore(supplier, metrics)
supplier.oldStores.UserTermsOfService = NewSqlUserTermsOfServiceStore(supplier)
supplier.oldStores.linkMetadata = NewSqlLinkMetadataStore(supplier)
initSqlSupplierReactions(supplier)
initSqlSupplierRoles(supplier)
@@ -183,6 +186,7 @@ func NewSqlSupplier(settings model.SqlSettings, metrics einterfaces.MetricsInter
supplier.oldStores.plugin.(*SqlPluginStore).CreateIndexesIfNotExists()
supplier.oldStores.TermsOfService.(SqlTermsOfServiceStore).CreateIndexesIfNotExists()
supplier.oldStores.UserTermsOfService.(SqlUserTermsOfServiceStore).CreateIndexesIfNotExists()
supplier.oldStores.linkMetadata.(*SqlLinkMetadataStore).CreateIndexesIfNotExists()
supplier.CreateIndexesIfNotExistsGroups()
@@ -1032,6 +1036,10 @@ func (ss *SqlSupplier) Group() store.GroupStore {
return ss.oldStores.group
}
func (ss *SqlSupplier) LinkMetadata() store.LinkMetadataStore {
return ss.oldStores.linkMetadata
}
func (ss *SqlSupplier) DropAllTables() {
ss.master.TruncateTables()
}
@@ -1051,6 +1059,10 @@ func (me mattermConverter) ToDb(val interface{}) (interface{}, error) {
return model.StringInterfaceToJson(t), nil
case map[string]interface{}:
return model.StringInterfaceToJson(model.StringInterface(t)), nil
case JSONSerializable:
return t.ToJson(), nil
case *opengraph.OpenGraph:
return json.Marshal(t)
}
return val, nil
@@ -1113,6 +1125,10 @@ func (me mattermConverter) FromDb(target interface{}) (gorp.CustomScanner, bool)
return gorp.CustomScanner{}, false
}
type JSONSerializable interface {
ToJson() string
}
func convertMySQLFullTextColumnsToPostgres(columnNames string) string {
columns := strings.Split(columnNames, ", ")
concatenatedColumnNames := ""