Skip to content
Snippets Groups Projects
Commit 208fcc31 authored by Jared Hancock's avatar Jared Hancock
Browse files

orm: Add options() method to influence compiler options

Disable sorting on ThreadEntry::email_info__mid lookups for email processing
which results in an on-disk temporary table.
parent 340fee7c
No related branches found
No related tags found
No related merge requests found
......@@ -919,6 +919,7 @@ class QuerySet implements IteratorAggregate, ArrayAccess, Serializable, Countabl
var $distinct = array();
var $lock = false;
var $chain = array();
var $options = array();
const LOCK_EXCLUSIVE = 1;
const LOCK_SHARED = 2;
......@@ -986,6 +987,9 @@ class QuerySet implements IteratorAggregate, ArrayAccess, Serializable, Countabl
return $this;
}
function order_by($order, $direction=false) {
if ($order === false)
return $this->options(array('nosort' => true));
$args = func_get_args();
if (in_array($direction, array(self::ASC, self::DESC))) {
$args = array($args[0]);
......@@ -1184,6 +1188,11 @@ class QuerySet implements IteratorAggregate, ArrayAccess, Serializable, Countabl
return $this;
}
function options($options) {
$this->options = array_merge($this->options, $options);
return $this;
}
function countSelectFields() {
$count = count($this->values) + count($this->annotations);
if (isset($this->extra['select']))
......@@ -1259,6 +1268,7 @@ class QuerySet implements IteratorAggregate, ArrayAccess, Serializable, Countabl
// Load defaults from model
$model = $this->model;
$query = clone $this;
$options += $this->options;
if ($options['nosort'])
$query->ordering = array();
elseif (!$query->ordering && $model::getMeta('ordering'))
......
......@@ -1128,6 +1128,7 @@ implements TemplateVariable {
// in-reply-to header
if ($entry = ThreadEntry::objects()
->filter(array('email_info__mid' => $mailinfo['mid']))
->order_by(false)
->first()
) {
$seen = true;
......@@ -1201,7 +1202,8 @@ implements TemplateVariable {
$mid = "$left@$right";
}
$entries = ThreadEntry::objects()
->filter(array('email_info__mid' => $mid));
->filter(array('email_info__mid' => $mid))
->order_by(false);
foreach ($entries as $t) {
// Capture the first match thread item
if (!$thread)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment