diff options
author | friendica <info@friendica.com> | 2012-01-02 16:54:37 -0800 |
---|---|---|
committer | friendica <info@friendica.com> | 2012-01-02 16:54:37 -0800 |
commit | 4c35a6b0d7e2f2431571d63888816ecff446d258 (patch) | |
tree | 88d274219b2cc3e04d213837ce464082579db67b /include/conversation.php | |
parent | f1ee5f48d4a0bb2f293c6c9a38ba71cbeb9d14fa (diff) | |
download | volse-hubzilla-4c35a6b0d7e2f2431571d63888816ecff446d258.tar.gz volse-hubzilla-4c35a6b0d7e2f2431571d63888816ecff446d258.tar.bz2 volse-hubzilla-4c35a6b0d7e2f2431571d63888816ecff446d258.zip |
conversation sql optimisations
Diffstat (limited to 'include/conversation.php')
-rw-r--r-- | include/conversation.php | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/include/conversation.php b/include/conversation.php index fae57c565..d40b2ea7e 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -884,3 +884,62 @@ function status_editor($a,$x, $notes_cid = 0) { return $o; } + + +function conv_sort($arr,$order) { + + if((!(is_array($arr) && count($arr)))) + return array(); + + $parents = array(); + + foreach($arr as $x) + if($x['id'] == $x['parent']) + $parents[] = $x; + + if(stristr($order,'created')) + usort($parents,'sort_thr_created'); + elseif(stristr($order,'commented')) + usort($parents,'sort_thr_commented'); + + foreach($parents as $x) + $x['children'] = array(); + + foreach($arr as $x) { + if($x['id'] != $x['parent']) { + $p = find_thread_parent_index($parents,$x); + $parents[$p]['children'][] = $x; + } + } + foreach($parents as $x) + if(count($x['children'])) + usort($x['children'],'sort_thr_created_rev'); + + $ret = array(); + foreach($parents as $x) { + $ret[] = $x; + foreach($x['children'] as $y) + $ret[] = $y; + } + + return $ret; +} + + +function sort_thr_created($a,$b) { + return strcmp($b['created'],$a['created']); +} + +function sort_thr_created_rev($a,$b) { + return strcmp($a['created'],$b['created']); +} + +function sort_thr_commented($a,$b) { + return strcmp($b['commented'],$a['commented']); +} + +function find_thread_parent_index($arr,$x) { + foreach($arr as $k => $v) + if($v['id'] == $x['parent']) + return $k; +}
\ No newline at end of file |