mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 18:27:13 +08:00
fix: 移除不必要的互斥锁
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
"github.com/goravel/framework/facades"
|
||||
|
||||
@@ -31,13 +29,10 @@ func (r *PluginController) List(ctx http.Context) http.Response {
|
||||
return ErrorSystem(ctx)
|
||||
}
|
||||
|
||||
var lock sync.RWMutex
|
||||
installedPluginsMap := make(map[string]models.Plugin)
|
||||
|
||||
for _, p := range installedPlugins {
|
||||
lock.Lock()
|
||||
installedPluginsMap[p.Slug] = p
|
||||
lock.Unlock()
|
||||
}
|
||||
|
||||
type plugin struct {
|
||||
@@ -111,28 +106,21 @@ func (r *PluginController) Install(ctx http.Context) http.Response {
|
||||
return Error(ctx, http.StatusUnprocessableEntity, "插件已安装")
|
||||
}
|
||||
|
||||
var lock sync.RWMutex
|
||||
pluginsMap := make(map[string]bool)
|
||||
|
||||
for _, p := range installedPlugins {
|
||||
lock.Lock()
|
||||
pluginsMap[p.Slug] = true
|
||||
lock.Unlock()
|
||||
}
|
||||
|
||||
for _, require := range plugin.Requires {
|
||||
lock.RLock()
|
||||
_, requireFound := pluginsMap[require]
|
||||
lock.RUnlock()
|
||||
if !requireFound {
|
||||
return Error(ctx, http.StatusForbidden, "插件 "+slug+" 需要依赖 "+require+" 插件")
|
||||
}
|
||||
}
|
||||
|
||||
for _, exclude := range plugin.Excludes {
|
||||
lock.RLock()
|
||||
_, excludeFound := pluginsMap[exclude]
|
||||
lock.RUnlock()
|
||||
if excludeFound {
|
||||
return Error(ctx, http.StatusForbidden, "插件 "+slug+" 不兼容 "+exclude+" 插件")
|
||||
}
|
||||
@@ -172,28 +160,21 @@ func (r *PluginController) Uninstall(ctx http.Context) http.Response {
|
||||
return Error(ctx, http.StatusUnprocessableEntity, "插件未安装")
|
||||
}
|
||||
|
||||
var lock sync.RWMutex
|
||||
pluginsMap := make(map[string]bool)
|
||||
|
||||
for _, p := range installedPlugins {
|
||||
lock.Lock()
|
||||
pluginsMap[p.Slug] = true
|
||||
lock.Unlock()
|
||||
}
|
||||
|
||||
for _, require := range plugin.Requires {
|
||||
lock.RLock()
|
||||
_, requireFound := pluginsMap[require]
|
||||
lock.RUnlock()
|
||||
if !requireFound {
|
||||
return Error(ctx, http.StatusForbidden, "插件 "+slug+" 需要依赖 "+require+" 插件")
|
||||
}
|
||||
}
|
||||
|
||||
for _, exclude := range plugin.Excludes {
|
||||
lock.RLock()
|
||||
_, excludeFound := pluginsMap[exclude]
|
||||
lock.RUnlock()
|
||||
if excludeFound {
|
||||
return Error(ctx, http.StatusForbidden, "插件 "+slug+" 不兼容 "+exclude+" 插件")
|
||||
}
|
||||
@@ -233,28 +214,21 @@ func (r *PluginController) Update(ctx http.Context) http.Response {
|
||||
return Error(ctx, http.StatusUnprocessableEntity, "插件未安装")
|
||||
}
|
||||
|
||||
var lock sync.RWMutex
|
||||
pluginsMap := make(map[string]bool)
|
||||
|
||||
for _, p := range installedPlugins {
|
||||
lock.Lock()
|
||||
pluginsMap[p.Slug] = true
|
||||
lock.Unlock()
|
||||
}
|
||||
|
||||
for _, require := range plugin.Requires {
|
||||
lock.RLock()
|
||||
_, requireFound := pluginsMap[require]
|
||||
lock.RUnlock()
|
||||
if !requireFound {
|
||||
return Error(ctx, http.StatusForbidden, "插件 "+slug+" 需要依赖 "+require+" 插件")
|
||||
}
|
||||
}
|
||||
|
||||
for _, exclude := range plugin.Excludes {
|
||||
lock.RLock()
|
||||
_, excludeFound := pluginsMap[exclude]
|
||||
lock.RUnlock()
|
||||
if excludeFound {
|
||||
return Error(ctx, http.StatusForbidden, "插件 "+slug+" 不兼容 "+exclude+" 插件")
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package middleware
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
|
||||
@@ -47,19 +46,14 @@ func MustInstall() http.Middleware {
|
||||
return
|
||||
}
|
||||
|
||||
var lock sync.RWMutex
|
||||
pluginsMap := make(map[string]bool)
|
||||
|
||||
for _, p := range installedPlugins {
|
||||
lock.Lock()
|
||||
pluginsMap[p.Slug] = true
|
||||
lock.Unlock()
|
||||
}
|
||||
|
||||
for _, require := range plugin.Requires {
|
||||
lock.RLock()
|
||||
_, requireFound := pluginsMap[require]
|
||||
lock.RUnlock()
|
||||
if !requireFound {
|
||||
ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{
|
||||
"code": http.StatusForbidden,
|
||||
@@ -70,9 +64,7 @@ func MustInstall() http.Middleware {
|
||||
}
|
||||
|
||||
for _, exclude := range plugin.Excludes {
|
||||
lock.RLock()
|
||||
_, excludeFound := pluginsMap[exclude]
|
||||
lock.RUnlock()
|
||||
if excludeFound {
|
||||
ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{
|
||||
"code": http.StatusForbidden,
|
||||
|
||||
@@ -8,14 +8,14 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/goravel/framework/support/carbon"
|
||||
internal2 "panel/internal"
|
||||
|
||||
"panel/app/models"
|
||||
"panel/internal"
|
||||
"panel/pkg/tools"
|
||||
)
|
||||
|
||||
type BackupImpl struct {
|
||||
setting internal2.Setting
|
||||
setting internal.Setting
|
||||
}
|
||||
|
||||
func NewBackupImpl() *BackupImpl {
|
||||
@@ -25,30 +25,30 @@ func NewBackupImpl() *BackupImpl {
|
||||
}
|
||||
|
||||
// WebsiteList 网站备份列表
|
||||
func (s *BackupImpl) WebsiteList() ([]internal2.BackupFile, error) {
|
||||
func (s *BackupImpl) WebsiteList() ([]internal.BackupFile, error) {
|
||||
backupPath := s.setting.Get(models.SettingKeyBackupPath)
|
||||
if len(backupPath) == 0 {
|
||||
return []internal2.BackupFile{}, nil
|
||||
return []internal.BackupFile{}, nil
|
||||
}
|
||||
|
||||
backupPath += "/website"
|
||||
if !tools.Exists(backupPath) {
|
||||
if err := tools.Mkdir(backupPath, 0644); err != nil {
|
||||
return []internal2.BackupFile{}, err
|
||||
return []internal.BackupFile{}, err
|
||||
}
|
||||
}
|
||||
|
||||
files, err := os.ReadDir(backupPath)
|
||||
if err != nil {
|
||||
return []internal2.BackupFile{}, err
|
||||
return []internal.BackupFile{}, err
|
||||
}
|
||||
var backupList []internal2.BackupFile
|
||||
var backupList []internal.BackupFile
|
||||
for _, file := range files {
|
||||
info, err := file.Info()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
backupList = append(backupList, internal2.BackupFile{
|
||||
backupList = append(backupList, internal.BackupFile{
|
||||
Name: file.Name(),
|
||||
Size: tools.FormatBytes(float64(info.Size())),
|
||||
})
|
||||
@@ -115,30 +115,30 @@ func (s *BackupImpl) WebsiteRestore(website models.Website, backupFile string) e
|
||||
}
|
||||
|
||||
// MysqlList MySQL备份列表
|
||||
func (s *BackupImpl) MysqlList() ([]internal2.BackupFile, error) {
|
||||
func (s *BackupImpl) MysqlList() ([]internal.BackupFile, error) {
|
||||
backupPath := s.setting.Get(models.SettingKeyBackupPath)
|
||||
if len(backupPath) == 0 {
|
||||
return []internal2.BackupFile{}, nil
|
||||
return []internal.BackupFile{}, nil
|
||||
}
|
||||
|
||||
backupPath += "/mysql"
|
||||
if !tools.Exists(backupPath) {
|
||||
if err := tools.Mkdir(backupPath, 0644); err != nil {
|
||||
return []internal2.BackupFile{}, err
|
||||
return []internal.BackupFile{}, err
|
||||
}
|
||||
}
|
||||
|
||||
files, err := os.ReadDir(backupPath)
|
||||
if err != nil {
|
||||
return []internal2.BackupFile{}, err
|
||||
return []internal.BackupFile{}, err
|
||||
}
|
||||
var backupList []internal2.BackupFile
|
||||
var backupList []internal.BackupFile
|
||||
for _, file := range files {
|
||||
info, err := file.Info()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
backupList = append(backupList, internal2.BackupFile{
|
||||
backupList = append(backupList, internal.BackupFile{
|
||||
Name: file.Name(),
|
||||
Size: tools.FormatBytes(float64(info.Size())),
|
||||
})
|
||||
@@ -228,30 +228,30 @@ func (s *BackupImpl) MysqlRestore(database string, backupFile string) error {
|
||||
}
|
||||
|
||||
// PostgresqlList PostgreSQL备份列表
|
||||
func (s *BackupImpl) PostgresqlList() ([]internal2.BackupFile, error) {
|
||||
func (s *BackupImpl) PostgresqlList() ([]internal.BackupFile, error) {
|
||||
backupPath := s.setting.Get(models.SettingKeyBackupPath)
|
||||
if len(backupPath) == 0 {
|
||||
return []internal2.BackupFile{}, nil
|
||||
return []internal.BackupFile{}, nil
|
||||
}
|
||||
|
||||
backupPath += "/postgresql"
|
||||
if !tools.Exists(backupPath) {
|
||||
if err := tools.Mkdir(backupPath, 0644); err != nil {
|
||||
return []internal2.BackupFile{}, err
|
||||
return []internal.BackupFile{}, err
|
||||
}
|
||||
}
|
||||
|
||||
files, err := os.ReadDir(backupPath)
|
||||
if err != nil {
|
||||
return []internal2.BackupFile{}, err
|
||||
return []internal.BackupFile{}, err
|
||||
}
|
||||
var backupList []internal2.BackupFile
|
||||
var backupList []internal.BackupFile
|
||||
for _, file := range files {
|
||||
info, err := file.Info()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
backupList = append(backupList, internal2.BackupFile{
|
||||
backupList = append(backupList, internal.BackupFile{
|
||||
Name: file.Name(),
|
||||
Size: tools.FormatBytes(float64(info.Size())),
|
||||
})
|
||||
|
||||
@@ -13,14 +13,14 @@ import (
|
||||
"github.com/goravel/framework/facades"
|
||||
"github.com/spf13/cast"
|
||||
requests "panel/app/http/requests/website"
|
||||
internal2 "panel/internal"
|
||||
|
||||
"panel/app/models"
|
||||
"panel/internal"
|
||||
"panel/pkg/tools"
|
||||
)
|
||||
|
||||
type WebsiteImpl struct {
|
||||
setting internal2.Setting
|
||||
setting internal.Setting
|
||||
}
|
||||
|
||||
func NewWebsiteImpl() *WebsiteImpl {
|
||||
@@ -41,7 +41,7 @@ func (r *WebsiteImpl) List(page, limit int) (int64, []models.Website, error) {
|
||||
}
|
||||
|
||||
// Add 添加网站
|
||||
func (r *WebsiteImpl) Add(website internal2.PanelWebsite) (models.Website, error) {
|
||||
func (r *WebsiteImpl) Add(website internal.PanelWebsite) (models.Website, error) {
|
||||
w := models.Website{
|
||||
Name: website.Name,
|
||||
Status: website.Status,
|
||||
@@ -500,18 +500,18 @@ func (r *WebsiteImpl) Delete(id uint) error {
|
||||
}
|
||||
|
||||
// GetConfig 获取网站配置
|
||||
func (r *WebsiteImpl) GetConfig(id uint) (internal2.WebsiteSetting, error) {
|
||||
func (r *WebsiteImpl) GetConfig(id uint) (internal.WebsiteSetting, error) {
|
||||
var website models.Website
|
||||
if err := facades.Orm().Query().Where("id", id).First(&website); err != nil {
|
||||
return internal2.WebsiteSetting{}, err
|
||||
return internal.WebsiteSetting{}, err
|
||||
}
|
||||
|
||||
config, err := tools.Read("/www/server/vhost/" + website.Name + ".conf")
|
||||
if err != nil {
|
||||
return internal2.WebsiteSetting{}, err
|
||||
return internal.WebsiteSetting{}, err
|
||||
}
|
||||
|
||||
var setting internal2.WebsiteSetting
|
||||
var setting internal.WebsiteSetting
|
||||
setting.Name = website.Name
|
||||
setting.Path = website.Path
|
||||
setting.Ssl = website.Ssl
|
||||
@@ -613,10 +613,10 @@ func (r *WebsiteImpl) GetConfig(id uint) (internal2.WebsiteSetting, error) {
|
||||
}
|
||||
|
||||
// GetConfigByName 根据网站名称获取网站配置
|
||||
func (r *WebsiteImpl) GetConfigByName(name string) (internal2.WebsiteSetting, error) {
|
||||
func (r *WebsiteImpl) GetConfigByName(name string) (internal.WebsiteSetting, error) {
|
||||
var website models.Website
|
||||
if err := facades.Orm().Query().Where("name", name).First(&website); err != nil {
|
||||
return internal2.WebsiteSetting{}, err
|
||||
return internal.WebsiteSetting{}, err
|
||||
}
|
||||
|
||||
return r.GetConfig(website.ID)
|
||||
|
||||
Reference in New Issue
Block a user