Update gorp to support query timeouts on postgres (#6730)

* Update gorp to support query timeouts on postgres

* Update help text to remove postgres exception

* Fix glide.lock
Этот коммит содержится в:
Joram Wilander
2017-06-28 10:34:00 -04:00
коммит произвёл Christopher Speller
родитель 2dea567dcf
Коммит 005dd0754b
7 изменённых файлов: 19 добавлений и 38 удалений

6
glide.lock сгенерированный
Просмотреть файл

@@ -1,5 +1,5 @@
hash: 8abe00d58923fa7855f666aac2a2ee1636aad6734c05e3b9895a084ff0f1b56c
updated: 2017-06-20T15:53:07.620238453-07:00
hash: 4c29ee4e38944411744a2a1af3e71836591d28feea24b328ab3d440a9ad1cef0
updated: 2017-06-23T08:58:13.944294825-04:00
imports:
- name: github.com/alecthomas/log4go
version: 3fbce08846379ec7f4f6bc7fce6dd01ce28fae4c
@@ -83,7 +83,7 @@ imports:
- name: github.com/magiconair/properties
version: 51463bfca2576e06c62a8504b5c0f06d61312647
- name: github.com/mattermost/gorp
version: cab337059e349c91a4b917c9be50708813619543
version: 995ddf2264c4ad45fbaf342f7500e4787ebae84a
- name: github.com/mattermost/rsc
version: bbaefb05eaa0389ea712340066837c8ce4d287f9
subpackages:

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

@@ -82,4 +82,4 @@ import:
- package: gopkg.in/olivere/elastic.v5
version: v5.0.41
- package: github.com/mattermost/gorp
version: cab337059e349c91a4b917c9be50708813619543
version: 995ddf2264c4ad45fbaf342f7500e4787ebae84a

1
vendor/github.com/mattermost/gorp/.gitignore сгенерированный поставляемый
Просмотреть файл

@@ -7,3 +7,4 @@ _obj
6.out
gorptest.bin
tmp
*.swp

21
vendor/github.com/mattermost/gorp/gorp.go сгенерированный поставляемый
Просмотреть файл

@@ -173,13 +173,9 @@ func exec(e SqlExecutor, query string, doTimeout bool, args ...interface{}) (sql
query, args = maybeExpandNamedQuery(dbMap, query, args)
}
if doTimeout && dbMap.Dialect.Name() != "PostgresDialect" {
ctx, cancel := context.WithTimeout(context.Background(), dbMap.QueryTimeout)
defer cancel()
return executor.ExecContext(ctx, query, args...)
} else {
return executor.Exec(query, args...)
}
ctx, cancel := context.WithTimeout(context.Background(), dbMap.QueryTimeout)
defer cancel()
return executor.ExecContext(ctx, query, args...)
}
// maybeExpandNamedQuery checks the given arg to see if it's eligible to be used
@@ -410,14 +406,9 @@ func get(m *DbMap, exec SqlExecutor, i interface{},
dest[x] = target
}
var row *sql.Row
if m.Dialect.Name() != "PostgresDialect" {
ctx, cancel := context.WithTimeout(context.Background(), m.QueryTimeout)
defer cancel()
row = exec.QueryRowContext(ctx, plan.query, keys...)
} else {
row = exec.QueryRow(plan.query, keys...)
}
ctx, cancel := context.WithTimeout(context.Background(), m.QueryTimeout)
defer cancel()
row := exec.QueryRowContext(ctx, plan.query, keys...)
err = row.Scan(dest...)
if err != nil {

23
vendor/github.com/mattermost/gorp/select.go сгенерированный поставляемый
Просмотреть файл

@@ -167,15 +167,9 @@ func selectVal(e SqlExecutor, holder interface{}, query string, args ...interfac
query, args = maybeExpandNamedQuery(dbMap, query, args)
}
var rows *sql.Rows
var err error
if dbMap.Dialect.Name() != "PostgresDialect" {
ctx, cancel := context.WithTimeout(context.Background(), dbMap.QueryTimeout)
defer cancel()
rows, err = e.QueryContext(ctx, query, args...)
} else {
rows, err = e.Query(query, args...)
}
ctx, cancel := context.WithTimeout(context.Background(), dbMap.QueryTimeout)
defer cancel()
rows, err := e.QueryContext(ctx, query, args...)
if err != nil {
return err
@@ -267,14 +261,9 @@ func rawselect(m *DbMap, exec SqlExecutor, i interface{}, query string,
}
// Run the query
var rows *sql.Rows
if m.Dialect.Name() != "PostgresDialect" {
ctx, cancel := context.WithTimeout(context.Background(), m.QueryTimeout)
defer cancel()
rows, err = exec.QueryContext(ctx, query, args...)
} else {
rows, err = exec.Query(query, args...)
}
ctx, cancel := context.WithTimeout(context.Background(), m.QueryTimeout)
defer cancel()
rows, err := exec.QueryContext(ctx, query, args...)
if err != nil {
return nil, err

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

@@ -142,7 +142,7 @@ export default class DatabaseSettings extends AdminSettings {
helpText={
<FormattedMessage
id='admin.sql.queryTimeoutDescription'
defaultMessage='The number of seconds to wait for a response from the database after opening a connection and sending the query. Errors that you see in the UI or in the logs as a result of a query timeout can vary depending on the type of query. This setting has no effect on PostgreSQL databases.'
defaultMessage='The number of seconds to wait for a response from the database after opening a connection and sending the query. Errors that you see in the UI or in the logs as a result of a query timeout can vary depending on the type of query.'
/>
}
value={this.state.queryTimeout}

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

@@ -832,7 +832,7 @@
"admin.sql.maxOpenTitle": "Maximum Open Connections:",
"admin.sql.noteDescription": "Changing properties in this section will require a server restart before taking effect.",
"admin.sql.noteTitle": "Note:",
"admin.sql.queryTimeoutDescription": "The number of seconds to wait for a response from the database after opening a connection and sending the query. Errors that you see in the UI or in the logs as a result of a query timeout can vary depending on the type of query. This setting has no effect on PostgreSQL databases.",
"admin.sql.queryTimeoutDescription": "The number of seconds to wait for a response from the database after opening a connection and sending the query. Errors that you see in the UI or in the logs as a result of a query timeout can vary depending on the type of query.",
"admin.sql.queryTimeoutExample": "E.g.: \"30\"",
"admin.sql.queryTimeoutTitle": "Query Timeout:",
"admin.sql.replicas": "Data Source Replicas:",