diff options
| author | fisharebest <fisharebest@gmail.com> | 2013-06-21 10:56:28 +0000 |
|---|---|---|
| committer | fisharebest <fisharebest@gmail.com> | 2013-06-21 10:56:28 +0000 |
| commit | d21cc07bb3c485545dc556e36751896da00cfb94 (patch) | |
| tree | b110a974d30d4bec946a50bf3099ebd6a9fd04e4 /library | |
| parent | d6ad7e5764b1e33447edb2b2b18b32ed7b4e5c6f (diff) | |
| download | webtrees-d21cc07bb3c485545dc556e36751896da00cfb94.tar.gz webtrees-d21cc07bb3c485545dc556e36751896da00cfb94.tar.bz2 webtrees-d21cc07bb3c485545dc556e36751896da00cfb94.zip | |
Performance - cache DB queries for pending changes
Diffstat (limited to 'library')
| -rw-r--r-- | library/WT/GedcomRecord.php | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/library/WT/GedcomRecord.php b/library/WT/GedcomRecord.php index 308ddcf175..80f9e40816 100644 --- a/library/WT/GedcomRecord.php +++ b/library/WT/GedcomRecord.php @@ -71,6 +71,7 @@ class WT_GedcomRecord { // been fetched previously). static public function getInstance($data) { global $gedcom_record_cache, $GEDCOM; + static $pending_record_cache; $is_pending=false; // Did this record come from a pending edit @@ -102,10 +103,27 @@ class WT_GedcomRecord { // Otherwise relationship privacy rules will not allow us to see // newly added records. if (WT_USER_CAN_EDIT) { - $tmp=find_updated_record($pid, $ged_id, true); - if ($tmp) { - $is_pending=true; - $data=$tmp; + if (!isset($pending_record_cache[$ged_id])) { + // Fetch all pending records in one database query + $pending_record_cache[$ged_id]=array(); + $rows = WT_DB::prepare( + "SELECT xref, new_gedcom FROM `##change` WHERE status='pending' AND gedcom_id=?" + )->execute(array($ged_id))->fetchAll(); + foreach ($rows as $row) { + $pending_record_cache[$ged_id][$row->xref] = $row->new_gedcom; + } + } + + if (isset($pending_record_cache[$ged_id][$pid])) { + // A pending edit exists for this record + $tmp = $pending_record_cache[$ged_id][$pid]; + // $tmp can be an empty string, indicating the record has + // a pending deletion. Ignore this, as we handle pending + // deletions separately. + if ($tmp) { + $is_pending=true; + $data=$tmp; + } } } |
