Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates a planlove table, which is auto-updated on plan changes. I'm still working on the front-end change to search.php to get it to actually use the table. As mentioned in Issue 138, quicklove runs a slow query - the MySQL fulltext index on edit_text isn't used because MySQL can't search for square brackets in fulltext indices. By keeping a cache of who planloves who, the search page can be greatly sped up. (For a rough estimate - obtained using php's microtime - 97.5% of quicklove's run time is spent waiting for the DB query to complete)
- Loading branch information
Showing
7 changed files
with
185 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
// Script to initially load the planlove table, in batches so the server doesn't run out of RAM. | ||
// Run it like this: $ for i in {0..75} ; do echo $i; php db/load_quicklove.php $i; done | ||
|
||
if (PHP_SAPI != 'cli') die(); | ||
|
||
require_once ('bootstrap.php'); | ||
if ($argc == 2 || $argc == 3) { | ||
$page = $argv[1]; | ||
if ($argc = 2) { | ||
$batchsize = 100; | ||
} else { | ||
$batchsize = $argv[2]; | ||
} | ||
$plans = Doctrine_Query::create()->select('a.*, p.*')->from('Accounts a')->leftJoin('a.Plan p') | ||
->limit($batchsize)->offset($page * $batchsize)->orderBy('a.userid asc')->execute(); | ||
foreach($plans as $plan) { | ||
set_time_limit(20); | ||
if ($plan->Plan) { | ||
//A trivial change, enough to force Doctrine to update itself. | ||
$plan->Plan->edit_text = $plan->Plan->edit_text; | ||
$plan->Plan->save(); | ||
}//if the user has a Plan. Not all do. (!) | ||
} //foreach plan | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
class PlanloveTable extends Doctrine_Migration_Base { | ||
public function migrate($direction) { | ||
$columns = array( | ||
'lover_id' => array( | ||
'type' => 'integer', | ||
'length' => 3, | ||
'unsigned' => 1, | ||
'notnull' => 1, | ||
'default' => 0 | ||
), | ||
|
||
'lovee_id' => array( | ||
'type' => 'integer', | ||
'length' => 3, | ||
'unsigned' => 1, | ||
'notnull' => 1, | ||
'default' => 0 | ||
) | ||
); | ||
$options = array( | ||
'type' => 'MyISAM', | ||
'indexes' => array( | ||
'unique' => array('fields' => array('lover_id', 'lovee_id'), 'type' => 'unique'), | ||
'lover' => array('fields' => array('lover_id')), | ||
'lovee' => array('fields' => array('lovee_id')) | ||
) | ||
); | ||
$this->table($direction,'planlove',$columns, $options); | ||
|
||
} | ||
/* | ||
* This function is disabled, because Doctrine provides no way to run it in batches and no way to free | ||
* RAM associated with query sets (other than the usual end-of-script free). | ||
* In testing this migration on a copy of the production database, the migration was repeatedly terminated | ||
* before it could complete because my dev server ran out of RAM. | ||
* Therefore, to load the planlove table initially, run batches in separate PHP processes. | ||
* A script to do so is available at /trunk/db/load_planlove.php. It accepts two args: the batch size and the page to load | ||
public function postUp() { | ||
//Hit each plan, allowing Doctrine to update the tables for us | ||
//Do them in batches of 100, so we don't run out of RAM. | ||
gc_enable(); | ||
$batchsize = 100; | ||
$plans = true; | ||
//Yay for abusing for loops. | ||
for ($page = 0; $plans; $page++) { | ||
$plans = Doctrine_Query::create()->select('a.*, p.*')->from('Accounts a')->leftJoin('a.Plan p')->limit($batchsize)->offset($page * $batchsize)->orderBy('a.userid asc')->execute(); | ||
foreach($plans as $plan) { | ||
set_time_limit(20); | ||
if ($plan->Plan) { | ||
$plan->Plan->edit_text = $plan->Plan->edit_text; | ||
$plan->Plan->save(); | ||
}//if the user has a Plan. Not all do. (!) | ||
}//for each plan in the batch | ||
gc_collect_cycles(); | ||
}//for each batch | ||
} */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* Planlove | ||
* | ||
* This class has been auto-generated by the Doctrine ORM Framework | ||
* | ||
* @package ##PACKAGE## | ||
* @subpackage ##SUBPACKAGE## | ||
* @author ##NAME## <##EMAIL##> | ||
* @version SVN: $Id: Builder.php 5845 2009-06-09 07:36:57Z jwage $ | ||
*/ | ||
class Planlove extends BasePlanlove | ||
{ | ||
public function setUp() { | ||
parent::setUp(); | ||
$this->hasOne('Accounts as Lover', array('local' => 'lover_id', 'foreign' => 'userid')); | ||
$this->hasOne('Accounts as Lovee', array('local' => 'lovee_id', 'foreign' => 'userid')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/** | ||
* BasePlanlove | ||
* | ||
* This class has been auto-generated by the Doctrine ORM Framework | ||
* | ||
* @property integer $lover | ||
* @property integer $lovee | ||
* | ||
* @package ##PACKAGE## | ||
* @subpackage ##SUBPACKAGE## | ||
* @author ##NAME## <##EMAIL##> | ||
* @version SVN: $Id: Builder.php 5845 2009-06-09 07:36:57Z jwage $ | ||
*/ | ||
abstract class BasePlanlove extends Doctrine_Record | ||
{ | ||
public function setTableDefinition() | ||
{ | ||
$this->setTableName('planlove'); | ||
$this->hasColumn('lover_id', 'integer', 3, array( | ||
'type' => 'integer', | ||
'length' => 3, | ||
'unsigned' => 1, | ||
'primary' => true, | ||
'autoincrement' => false, | ||
)); | ||
$this->hasColumn('lovee_id', 'integer', 3, array( | ||
'type' => 'integer', | ||
'length' => 3, | ||
'unsigned' => 1, | ||
'primary' => true, | ||
'autoincrement' => false, | ||
)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters