From 517342ab9fa08aa66fd26b3002310e89179df436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9C=A8=E4=B8=8B=E9=82=B5=E5=AE=81?= Date: Mon, 18 Nov 2024 19:42:59 +0800 Subject: [PATCH] optimize query methods from Find to First --- configmanage/server/internal/configinfo.go | 2 +- configmanage/server/internal/dnsfile.go | 6 +++--- configmanage/server/internal/hostfile.go | 6 +++--- configmanage/server/internal/repofile.go | 6 +++--- configmanage/server/internal/ssh.go | 4 ++-- configmanage/server/internal/sshd.go | 6 +++--- configmanage/server/internal/sysctl.go | 6 +++--- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/configmanage/server/internal/configinfo.go b/configmanage/server/internal/configinfo.go index f8fba695..e26b2a45 100644 --- a/configmanage/server/internal/configinfo.go +++ b/configmanage/server/internal/configinfo.go @@ -27,7 +27,7 @@ func (cm *ConfigInfo) Add() error { func GetInfoByUUID(uuid string) (ConfigInfo, error) { var ci ConfigInfo - err := db.MySQL().Model(&ConfigInfo{}).Where("uuid=?", uuid).Find(&ci).Error + err := db.MySQL().Model(&ConfigInfo{}).Where("uuid=?", uuid).First(&ci).Error return ci, err } diff --git a/configmanage/server/internal/dnsfile.go b/configmanage/server/internal/dnsfile.go index a9d4ccd1..755cdfca 100644 --- a/configmanage/server/internal/dnsfile.go +++ b/configmanage/server/internal/dnsfile.go @@ -52,15 +52,15 @@ func (df *DNSFile) Add() error { func GetDNSFileByInfoUUID(uuid string, isindex interface{}) (DNSFile, error) { var file DNSFile if isindex != nil { - err := db.MySQL().Model(&DNSFile{}).Where("config_info_uuid=? && is_index = ?", uuid, isindex).Find(&file).Error + err := db.MySQL().Model(&DNSFile{}).Where("config_info_uuid=? && is_index = ?", uuid, isindex).First(&file).Error return file, err } - err := db.MySQL().Model(&DNSFile{}).Where("config_info_uuid=?", uuid).Find(&file).Error + err := db.MySQL().Model(&DNSFile{}).Where("config_info_uuid=?", uuid).First(&file).Error return file, err } func GetDNSFileByUUID(uuid string) (DNSFile, error) { var file DNSFile - err := db.MySQL().Model(&DNSFile{}).Where("uuid=?", uuid).Find(&file).Error + err := db.MySQL().Model(&DNSFile{}).Where("uuid=?", uuid).First(&file).Error return file, err } diff --git a/configmanage/server/internal/hostfile.go b/configmanage/server/internal/hostfile.go index b37b3408..d06b670b 100644 --- a/configmanage/server/internal/hostfile.go +++ b/configmanage/server/internal/hostfile.go @@ -53,16 +53,16 @@ func (hf *HostFile) Add() error { func GetHostFileByInfoUUID(uuid string, isindex interface{}) (HostFile, error) { var file HostFile if isindex != nil { - err := db.MySQL().Model(&HostFile{}).Where("config_info_uuid=? && is_index = ?", uuid, isindex).Find(&file).Error + err := db.MySQL().Model(&HostFile{}).Where("config_info_uuid=? && is_index = ?", uuid, isindex).First(&file).Error return file, err } - err := db.MySQL().Model(&HostFile{}).Where("config_info_uuid=?", uuid).Find(&file).Error + err := db.MySQL().Model(&HostFile{}).Where("config_info_uuid=?", uuid).First(&file).Error return file, err } func GetHostFileByUUID(uuid string) (HostFile, error) { var file HostFile - err := db.MySQL().Model(&HostFile{}).Where("uuid=?", uuid).Find(&file).Error + err := db.MySQL().Model(&HostFile{}).Where("uuid=?", uuid).First(&file).Error return file, err } diff --git a/configmanage/server/internal/repofile.go b/configmanage/server/internal/repofile.go index 872962b4..a4e7d07e 100644 --- a/configmanage/server/internal/repofile.go +++ b/configmanage/server/internal/repofile.go @@ -29,16 +29,16 @@ func (rf *RepoFile) Add() error { func GetRepoFileByInfoUUID(uuid string, isindex interface{}) (RepoFile, error) { var file RepoFile if isindex != nil { - err := db.MySQL().Model(&RepoFile{}).Where("config_info_uuid=? && is_index = ?", uuid, isindex).Find(&file).Error + err := db.MySQL().Model(&RepoFile{}).Where("config_info_uuid=? && is_index = ?", uuid, isindex).First(&file).Error return file, err } - err := db.MySQL().Model(&RepoFile{}).Where("config_info_uuid=?", uuid).Find(&file).Error + err := db.MySQL().Model(&RepoFile{}).Where("config_info_uuid=?", uuid).First(&file).Error return file, err } func GetRepoFileByUUID(uuid string) (RepoFile, error) { var file RepoFile - err := db.MySQL().Model(&RepoFile{}).Where("uuid=?", uuid).Find(&file).Error + err := db.MySQL().Model(&RepoFile{}).Where("uuid=?", uuid).First(&file).Error return file, err } diff --git a/configmanage/server/internal/ssh.go b/configmanage/server/internal/ssh.go index b206c01e..1a80f7fb 100644 --- a/configmanage/server/internal/ssh.go +++ b/configmanage/server/internal/ssh.go @@ -29,10 +29,10 @@ func (sf *SSHFile) Add() error { func GetSSHFileByInfoUUID(uuid string, isindex interface{}) (SSHFile, error) { var file SSHFile if isindex != nil { - err := db.MySQL().Model(&SSHFile{}).Where("config_info_uuid=? && is_index = ?", uuid, isindex).Find(&file).Error + err := db.MySQL().Model(&SSHFile{}).Where("config_info_uuid=? && is_index = ?", uuid, isindex).First(&file).Error return file, err } - err := db.MySQL().Model(&SSHFile{}).Where("config_info_uuid=?", uuid).Find(&file).Error + err := db.MySQL().Model(&SSHFile{}).Where("config_info_uuid=?", uuid).First(&file).Error return file, err } diff --git a/configmanage/server/internal/sshd.go b/configmanage/server/internal/sshd.go index 47ea0c7f..942788a2 100644 --- a/configmanage/server/internal/sshd.go +++ b/configmanage/server/internal/sshd.go @@ -28,16 +28,16 @@ func (sdf *SSHDFile) Add() error { func GetSSHDFileByInfoUUID(uuid string, isindex interface{}) (SSHDFile, error) { var file SSHDFile if isindex != nil { - err := db.MySQL().Model(&SSHDFile{}).Where("config_info_uuid=? && is_index = ?", uuid, isindex).Find(&file).Error + err := db.MySQL().Model(&SSHDFile{}).Where("config_info_uuid=? && is_index = ?", uuid, isindex).First(&file).Error return file, err } - err := db.MySQL().Model(&SSHDFile{}).Where("config_info_uuid=?", uuid).Find(&file).Error + err := db.MySQL().Model(&SSHDFile{}).Where("config_info_uuid=?", uuid).First(&file).Error return file, err } func GetSSHDFileByUUID(uuid string) (SSHDFile, error) { var file SSHDFile - err := db.MySQL().Model(&SSHDFile{}).Where("uuid=?", uuid).Find(&file).Error + err := db.MySQL().Model(&SSHDFile{}).Where("uuid=?", uuid).First(&file).Error return file, err } diff --git a/configmanage/server/internal/sysctl.go b/configmanage/server/internal/sysctl.go index 943b8cf7..9eb2511a 100644 --- a/configmanage/server/internal/sysctl.go +++ b/configmanage/server/internal/sysctl.go @@ -29,16 +29,16 @@ func (sysf *SysctlFile) Add() error { func GetSysctlFileByInfoUUID(uuid string, isindex interface{}) (SysctlFile, error) { var file SysctlFile if isindex != nil { - err := db.MySQL().Model(&SysctlFile{}).Where("config_info_uuid=? && is_index = ?", uuid, isindex).Find(&file).Error + err := db.MySQL().Model(&SysctlFile{}).Where("config_info_uuid=? && is_index = ?", uuid, isindex).First(&file).Error return file, err } - err := db.MySQL().Model(&SysctlFile{}).Where("config_info_uuid=?", uuid).Find(&file).Error + err := db.MySQL().Model(&SysctlFile{}).Where("config_info_uuid=?", uuid).First(&file).Error return file, err } func GetSysctlFileByUUID(uuid string) (SysctlFile, error) { var file SysctlFile - err := db.MySQL().Model(&SysctlFile{}).Where("uuid=?", uuid).Find(&file).Error + err := db.MySQL().Model(&SysctlFile{}).Where("uuid=?", uuid).First(&file).Error return file, err } -- Gitee