mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-23 08:56:29 +00:00
optimize postgres query
This commit is contained in:
parent
4f5c53f9ee
commit
360708e93d
4 changed files with 14 additions and 82 deletions
|
@ -1,17 +1,3 @@
|
|||
// Copyright 2018 Drone.IO Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package mysql
|
||||
|
||||
// Lookup returns the named statement.
|
||||
|
|
|
@ -1,34 +1,14 @@
|
|||
-- name: feed-latest-build
|
||||
|
||||
SELECT
|
||||
repo_owner
|
||||
,repo_name
|
||||
,repo_full_name
|
||||
,build_number
|
||||
,build_event
|
||||
,build_status
|
||||
,build_created
|
||||
,build_started
|
||||
,build_finished
|
||||
,build_commit
|
||||
,build_branch
|
||||
,build_ref
|
||||
,build_refspec
|
||||
,build_remote
|
||||
,build_title
|
||||
,build_message
|
||||
,build_author
|
||||
,build_email
|
||||
,build_avatar
|
||||
FROM repos LEFT OUTER JOIN builds ON build_id = (
|
||||
SELECT build_id FROM builds
|
||||
WHERE builds.build_repo_id = repos.repo_id
|
||||
ORDER BY build_id DESC
|
||||
LIMIT 1
|
||||
)
|
||||
SELECT repo_owner, repo_name, repo_full_name, b.*
|
||||
FROM repos LEFT OUTER JOIN (
|
||||
SELECT DISTINCT ON (build_repo_id) build_repo_id, build_id, build_number, build_event, build_status, build_created, build_started, build_finished, build_commit, build_branch, build_ref, build_refspec, build_remote, build_title, build_message, build_author, build_email, build_avatar
|
||||
FROM builds
|
||||
ORDER BY build_repo_id, build_id DESC
|
||||
) b ON b.build_repo_id = repos.repo_id
|
||||
INNER JOIN perms ON perms.perm_repo_id = repos.repo_id
|
||||
WHERE perms.perm_user_id = $1
|
||||
AND repos.repo_active = true
|
||||
AND repos.repo_active = TRUE
|
||||
ORDER BY repo_full_name ASC;
|
||||
|
||||
-- name: feed
|
||||
|
|
|
@ -98,35 +98,15 @@ SELECT currval('builds_build_id_seq');
|
|||
`
|
||||
|
||||
var feedLatestBuild = `
|
||||
SELECT
|
||||
repo_owner
|
||||
,repo_name
|
||||
,repo_full_name
|
||||
,build_number
|
||||
,build_event
|
||||
,build_status
|
||||
,build_created
|
||||
,build_started
|
||||
,build_finished
|
||||
,build_commit
|
||||
,build_branch
|
||||
,build_ref
|
||||
,build_refspec
|
||||
,build_remote
|
||||
,build_title
|
||||
,build_message
|
||||
,build_author
|
||||
,build_email
|
||||
,build_avatar
|
||||
FROM repos LEFT OUTER JOIN builds ON build_id = (
|
||||
SELECT build_id FROM builds
|
||||
WHERE builds.build_repo_id = repos.repo_id
|
||||
ORDER BY build_id DESC
|
||||
LIMIT 1
|
||||
)
|
||||
SELECT repo_owner, repo_name, repo_full_name, b.*
|
||||
FROM repos LEFT OUTER JOIN (
|
||||
SELECT DISTINCT ON (build_repo_id) build_repo_id, build_id, build_number, build_event, build_status, build_created, build_started, build_finished, build_commit, build_branch, build_ref, build_refspec, build_remote, build_title, build_message, build_author, build_email, build_avatar
|
||||
FROM builds
|
||||
ORDER BY build_repo_id, build_id DESC
|
||||
) b ON b.build_repo_id = repos.repo_id
|
||||
INNER JOIN perms ON perms.perm_repo_id = repos.repo_id
|
||||
WHERE perms.perm_user_id = $1
|
||||
AND repos.repo_active = true
|
||||
AND repos.repo_active = TRUE
|
||||
ORDER BY repo_full_name ASC;
|
||||
`
|
||||
|
||||
|
|
|
@ -1,17 +1,3 @@
|
|||
// Copyright 2018 Drone.IO Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package sqlite
|
||||
|
||||
// Lookup returns the named statement.
|
||||
|
|
Loading…
Reference in a new issue