Browse Source

MySQL reduce `UseDatabase` func calls

Vova Tkach 5 years ago
parent
commit
a3d82a3d75
2 changed files with 23 additions and 23 deletions
  1. 8 8
      engine/engine.go
  2. 15 15
      engine/modules/modules.go

+ 8 - 8
engine/engine.go

@@ -62,12 +62,19 @@ func (this *Engine) Process() bool {
 		return true
 	}
 
+	// Check for MySQL connection
+	err := this.Wrap.UseDatabase()
+	if err != nil {
+		utils.SystemErrorPageEngine(this.Wrap.W, err)
+		return true
+	}
+
 	// Separated logic
 	if !this.Wrap.IsBackend {
 		// Maintenance mode
 		if this.Wrap.Config.Engine.Maintenance != 0 {
 			if this.Wrap.User == nil {
-				this.Wrap.UseDatabase()
+				// this.Wrap.UseDatabase()
 				this.Wrap.LoadSessionUser()
 			}
 			if this.Wrap.User == nil {
@@ -88,13 +95,6 @@ func (this *Engine) Process() bool {
 		return this.Mods.XXXFrontEnd(this.Wrap)
 	}
 
-	// Backend must use MySQL anyway, so, check and connect
-	err := this.Wrap.UseDatabase()
-	if err != nil {
-		utils.SystemErrorPageEngine(this.Wrap.W, err)
-		return true
-	}
-
 	// Show login page if need
 	if this.Wrap.S.GetInt("UserId", 0) <= 0 {
 		// Redirect

+ 15 - 15
engine/modules/modules.go

@@ -296,14 +296,14 @@ func (this *Modules) XXXActionFire(wrap *wrapper.Wrapper) bool {
 			}
 			if name != "" {
 				if act, ok := this.acts[name]; ok {
-					if act.Info.WantDB {
-						err := wrap.UseDatabase()
-						if err != nil {
-							this.XXXActionHeaders(wrap, http.StatusNotFound)
-							wrap.MsgError(err.Error())
-							return true
-						}
-					}
+					// if act.Info.WantDB {
+					// 	err := wrap.UseDatabase()
+					// 	if err != nil {
+					// 		this.XXXActionHeaders(wrap, http.StatusNotFound)
+					// 		wrap.MsgError(err.Error())
+					// 		return true
+					// 	}
+					// }
 					if act.Info.WantUser || act.Info.WantAdmin {
 						if !wrap.LoadSessionUser() {
 							this.XXXActionHeaders(wrap, http.StatusNotFound)
@@ -344,13 +344,13 @@ func (this *Modules) XXXFrontEnd(wrap *wrapper.Wrapper) bool {
 	if mod != nil {
 		wrap.CurrModule = cm
 		if mod.Front != nil {
-			if mod.Info.WantDB {
-				err := wrap.UseDatabase()
-				if err != nil {
-					utils.SystemErrorPageEngine(wrap.W, err)
-					return true
-				}
-			}
+			// if mod.Info.WantDB {
+			// 	err := wrap.UseDatabase()
+			// 	if err != nil {
+			// 		utils.SystemErrorPageEngine(wrap.W, err)
+			// 		return true
+			// 	}
+			// }
 			start := time.Now()
 			mod.Front(wrap)
 			if !(mod.Info.Mount == "api" || (mod.Info.Mount == "shop" && len(wrap.UrlArgs) >= 3 && wrap.UrlArgs[1] == "basket")) {