mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
removed alternative_instance_get() (only used for gallery-hack)
refactored query-caching in instance_get() to just cache the raw db fields (unlikely to change) - overzealous caching was causing problems with wrong SQL selects on subsequent calls git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@50704 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
4dd4bc41a6
commit
844fe81cca
@ -53,6 +53,14 @@ class File extends DataObject {
|
|||||||
"BackLinkTracking" => "SiteTree",
|
"BackLinkTracking" => "SiteTree",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cached result of a "SHOW FIELDS" call
|
||||||
|
* in instance_get() for performance reasons.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected static $cache_file_fields = null;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the maximum
|
* Set the maximum
|
||||||
@ -609,29 +617,29 @@ class File extends DataObject {
|
|||||||
* @todo Admittedly this is a bit of a hack; but we need a way of ensuring that large
|
* @todo Admittedly this is a bit of a hack; but we need a way of ensuring that large
|
||||||
* TEXT fields don't stuff things up for the rest of us. Perhaps a separate search table would
|
* TEXT fields don't stuff things up for the rest of us. Perhaps a separate search table would
|
||||||
* be a better way of approaching this?
|
* be a better way of approaching this?
|
||||||
|
* @deprecated alternative_instance_get()
|
||||||
*/
|
*/
|
||||||
public function instance_get($filter = "", $sort = "", $join = "", $limit="", $containerClass = "DataObjectSet", $having="") {
|
public function instance_get($filter = "", $sort = "", $join = "", $limit="", $containerClass = "DataObjectSet", $having="") {
|
||||||
if($this->hasMethod('alternative_instance_get')) return $this->alternative_instance_get($filter, $sort, $join, $limit, $containerClass, $having);
|
|
||||||
|
|
||||||
$query = $this->extendedSQL($filter, $sort, $limit, $join, $having);
|
$query = $this->extendedSQL($filter, $sort, $limit, $join, $having);
|
||||||
$baseTable = reset($query->from);
|
$baseTable = reset($query->from);
|
||||||
|
|
||||||
|
$excludeDbColumns = array('Content');
|
||||||
|
|
||||||
// Work out which columns we're actually going to select
|
// Work out which columns we're actually going to select
|
||||||
// In short, we select everything except File.Content
|
// In short, we select everything except File.Content
|
||||||
if(!self::$dataobject_select) {
|
$filteredSelect = array();
|
||||||
self::$dataobject_select = array();
|
foreach($query->select as $i => $item) {
|
||||||
foreach($query->select as $item) {
|
if($item == "`File`.*") {
|
||||||
if($item == "`File`.*") {
|
if(!isset(self::$cache_file_fields)) self::$cache_file_fields = DB::query("SHOW FIELDS IN `File`")->column();
|
||||||
$fileColumns = DB::query("SHOW FIELDS IN `File`")->column();
|
$columnsToAdd = array_diff(self::$cache_file_fields, $excludeDbColumns);
|
||||||
$columnsToAdd = array_diff($fileColumns, array('Content'));
|
foreach($columnsToAdd as $otherItem) {
|
||||||
foreach($columnsToAdd as $otherItem) self::$dataobject_select[] = '`File`.' . $otherItem;
|
$filteredSelect[] = '`File`.' . $otherItem;
|
||||||
} else {
|
|
||||||
self::$dataobject_select[] = $item;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$filteredSelect[] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$query->select = $filteredSelect;
|
||||||
$query->select = self::$dataobject_select;
|
|
||||||
|
|
||||||
$records = $query->execute();
|
$records = $query->execute();
|
||||||
$ret = $this->buildDataObjectSet($records, $containerClass);
|
$ret = $this->buildDataObjectSet($records, $containerClass);
|
||||||
@ -646,6 +654,12 @@ class File extends DataObject {
|
|||||||
function userCanEdit() {
|
function userCanEdit() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function flushCache() {
|
||||||
|
parent::flushCache();
|
||||||
|
|
||||||
|
unset(self::$cache_file_fields);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user