Преглед изворни кода

Merge pull request #1316 from Alkarex/initial-requests

Remove superflous SQL category request
Alexandre Alapetite пре 9 година
родитељ
комит
9ed59ff1f3
3 измењених фајлова са 19 додато и 5 уклоњено
  1. 3 1
      CHANGELOG.md
  2. 5 0
      app/Controllers/indexController.php
  3. 11 4
      app/Models/Context.php

+ 3 - 1
CHANGELOG.md

@@ -33,8 +33,10 @@
 * UI
 * UI
 	* Download icon 💾 for podcasts [#1236](https://github.com/FreshRSS/FreshRSS/issues/1236)
 	* Download icon 💾 for podcasts [#1236](https://github.com/FreshRSS/FreshRSS/issues/1236)
 * Extensions
 * Extensions
-	* Allow extensions for default accout in anonymous mode [#1288](https://github.com/FreshRSS/FreshRSS/pull/1288)
+	* Allow extensions for default account in anonymous mode [#1288](https://github.com/FreshRSS/FreshRSS/pull/1288)
 	* Trigger a `freshrss:load-more` JavaScript event to help extensions [#1278](https://github.com/FreshRSS/FreshRSS/issues/1278)
 	* Trigger a `freshrss:load-more` JavaScript event to help extensions [#1278](https://github.com/FreshRSS/FreshRSS/issues/1278)
+* SQL
+	* Increase performances by removing a superfluous category request [#1316](https://github.com/FreshRSS/FreshRSS/pull/1316)
 * Mics.
 * Mics.
 	* Removed *resource-priorities* attributes (`defer`, `lazyload`), deprecated by W3C [#1222](https://github.com/FreshRSS/FreshRSS/pull/1222)
 	* Removed *resource-priorities* attributes (`defer`, `lazyload`), deprecated by W3C [#1222](https://github.com/FreshRSS/FreshRSS/pull/1222)
 
 

+ 5 - 0
app/Controllers/indexController.php

@@ -159,6 +159,11 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 	 *   - hours (default: 0)
 	 *   - hours (default: 0)
 	 */
 	 */
 	private function updateContext() {
 	private function updateContext() {
+		if (empty(FreshRSS_Context::$categories)) {
+			$catDAO = new FreshRSS_CategoryDAO();
+			FreshRSS_Context::$categories = $catDAO->listCategories();
+		}
+
 		// Update number of read / unread variables.
 		// Update number of read / unread variables.
 		$entryDAO = FreshRSS_Factory::createEntryDao();
 		$entryDAO = FreshRSS_Factory::createEntryDao();
 		FreshRSS_Context::$total_starred = $entryDAO->countUnreadReadFavorites();
 		FreshRSS_Context::$total_starred = $entryDAO->countUnreadReadFavorites();

+ 11 - 4
app/Models/Context.php

@@ -48,9 +48,6 @@ class FreshRSS_Context {
 		// Init configuration.
 		// Init configuration.
 		self::$system_conf = Minz_Configuration::get('system');
 		self::$system_conf = Minz_Configuration::get('system');
 		self::$user_conf = Minz_Configuration::get('user');
 		self::$user_conf = Minz_Configuration::get('user');
-
-		$catDAO = new FreshRSS_CategoryDAO();
-		self::$categories = $catDAO->listCategories();
 	}
 	}
 
 
 	/**
 	/**
@@ -142,6 +139,11 @@ class FreshRSS_Context {
 		$id = substr($get, 2);
 		$id = substr($get, 2);
 		$nb_unread = 0;
 		$nb_unread = 0;
 
 
+		if (empty(self::$categories)) {
+			$catDAO = new FreshRSS_CategoryDAO();
+			self::$categories = $catDAO->listCategories();
+		}
+
 		switch($type) {
 		switch($type) {
 		case 'a':
 		case 'a':
 			self::$current_get['all'] = true;
 			self::$current_get['all'] = true;
@@ -203,11 +205,16 @@ class FreshRSS_Context {
 	/**
 	/**
 	 * Set the value of $next_get attribute.
 	 * Set the value of $next_get attribute.
 	 */
 	 */
-	public static function _nextGet() {
+	private static function _nextGet() {
 		$get = self::currentGet();
 		$get = self::currentGet();
 		// By default, $next_get == $get
 		// By default, $next_get == $get
 		self::$next_get = $get;
 		self::$next_get = $get;
 
 
+		if (empty(self::$categories)) {
+			$catDAO = new FreshRSS_CategoryDAO();
+			self::$categories = $catDAO->listCategories();
+		}
+
 		if (self::$user_conf->onread_jump_next && strlen($get) > 2) {
 		if (self::$user_conf->onread_jump_next && strlen($get) > 2) {
 			$another_unread_id = '';
 			$another_unread_id = '';
 			$found_current_get = false;
 			$found_current_get = false;