From a08490364d081ff5030ab45d612235cb0ed6299c Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind@owncloud.com>
Date: Tue, 15 Jan 2013 20:20:39 +0100
Subject: [PATCH] Cache prepared statements in OC_DB

---
 lib/db.php | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lib/db.php b/lib/db.php
index 74e7ca5b0e..c5908afe69 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -41,6 +41,8 @@ class OC_DB {
 	const BACKEND_PDO=0;
 	const BACKEND_MDB2=1;
 
+	static private $preparedQueries = array();
+
 	/**
 	 * @var MDB2_Driver_Common
 	 */
@@ -321,7 +323,12 @@ class OC_DB {
 					$query.=$limitsql;
 				}
 			}
+		} else {
+			if (isset(self::$preparedQueries[$query])) {
+				return self::$preparedQueries[$query];
+			}
 		}
+		$rawQuery = $query;
 
 		// Optimize the query
 		$query = self::processQuery( $query );
@@ -343,6 +350,9 @@ class OC_DB {
 			}
 			$result=new PDOStatementWrapper($result);
 		}
+		if (is_null($limit) || $limit == -1) {
+			self::$preparedQueries[$rawQuery] = $result;
+		}
 		return $result;
 	}
 
-- 
GitLab