mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 10:15:35 +01:00
Improve the performance of artifact related APIs
Improve the performance of artifact related APIs by adding indexes and refactoring sql logic Closes #13890 #14813 #14814 Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
parent
08ed886936
commit
dc059a9a8f
@ -1,2 +1,7 @@
|
|||||||
ALTER TABLE replication_policy ADD COLUMN IF NOT EXISTS dest_namespace_replace_count int;
|
ALTER TABLE replication_policy ADD COLUMN IF NOT EXISTS dest_namespace_replace_count int;
|
||||||
UPDATE replication_policy SET dest_namespace_replace_count=-1 WHERE dest_namespace IS NULL;
|
UPDATE replication_policy SET dest_namespace_replace_count=-1 WHERE dest_namespace IS NULL;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_artifact_push_time ON artifact (push_time);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_tag_push_time ON tag (push_time);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_tag_artifact_id ON tag (artifact_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_artifact_reference_child_id ON artifact_reference (child_id);
|
@ -53,22 +53,22 @@ type DAO interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// both tagged and untagged artifacts
|
// the QuerySetter of beego doesn't support "EXISTS" directly, use qs.FilterRaw("id", "=id AND xxx") to workaround the limitation
|
||||||
both = `IN (
|
// base filter: both tagged and untagged artifacts
|
||||||
SELECT DISTINCT art.id FROM artifact art
|
both = `=id AND (
|
||||||
LEFT JOIN tag ON art.id=tag.artifact_id
|
EXISTS (SELECT 1 FROM tag WHERE tag.artifact_id = T0.id)
|
||||||
LEFT JOIN artifact_reference ref ON art.id=ref.child_id
|
OR
|
||||||
WHERE tag.id IS NOT NULL OR ref.id IS NULL)`
|
NOT EXISTS (SELECT 1 FROM artifact_reference ref WHERE ref.child_id = T0.id)
|
||||||
// only untagged artifacts
|
)`
|
||||||
untagged = `IN (
|
// tag filter: only untagged artifacts
|
||||||
SELECT DISTINCT art.id FROM artifact art
|
// the "untagged" filter is based on "base" filter, so we consider the tag only
|
||||||
LEFT JOIN tag ON art.id=tag.artifact_id
|
untagged = `=id AND NOT EXISTS(
|
||||||
WHERE tag.id IS NULL)`
|
SELECT 1 FROM tag WHERE tag.artifact_id = T0.id
|
||||||
// only tagged artifacts
|
)`
|
||||||
tagged = `IN (
|
// tag filter: only tagged artifacts
|
||||||
SELECT DISTINCT art.id FROM artifact art
|
tagged = `=id AND EXISTS (
|
||||||
JOIN tag ON art.id=tag.artifact_id
|
SELECT 1 FROM tag WHERE tag.artifact_id = T0.id
|
||||||
WHERE tag.id IS NOT NULL)`
|
)`
|
||||||
)
|
)
|
||||||
|
|
||||||
// New returns an instance of the default DAO
|
// New returns an instance of the default DAO
|
||||||
@ -273,7 +273,7 @@ func querySetter(ctx context.Context, query *q.Query) (beegoorm.QuerySeter, erro
|
|||||||
|
|
||||||
// handle q=base=*
|
// handle q=base=*
|
||||||
// when "q=base=*" is specified in the query, the base collection is the all artifacts of database,
|
// when "q=base=*" is specified in the query, the base collection is the all artifacts of database,
|
||||||
// otherwise the base connection is only the tagged artifacts and untagged artifacts that aren't
|
// otherwise the base collection is only the tagged artifacts and untagged artifacts that aren't
|
||||||
// referenced by others
|
// referenced by others
|
||||||
func setBaseQuery(qs beegoorm.QuerySeter, query *q.Query) (beegoorm.QuerySeter, error) {
|
func setBaseQuery(qs beegoorm.QuerySeter, query *q.Query) (beegoorm.QuerySeter, error) {
|
||||||
if query == nil || len(query.Keywords) == 0 {
|
if query == nil || len(query.Keywords) == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user