summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--browse.php1
-rwxr-xr-xdocs/CHANGELOG.md1
-rw-r--r--lib/class/query.class.php57
3 files changed, 57 insertions, 2 deletions
diff --git a/browse.php b/browse.php
index ed8b94be..e5994c38 100644
--- a/browse.php
+++ b/browse.php
@@ -63,6 +63,7 @@ switch($_REQUEST['action']) {
$browse->show_objects();
break;
case 'tag':
+ //FIXME: This whole thing is ugly, even though it works.
$browse->set_sort('count','ASC');
// This one's a doozy
$browse->set_simple_browse(false);
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 4cf79003..1e7cccc5 100755
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -3,6 +3,7 @@ CHANGELOG
3.6-FUTURE
----------
+- Improved storage efficiency for large browse results
- Fixed unnecessary growth of the tmp_browse table from API usage (reported
by Ondalf)
- Removed external module 'validateEmail'
diff --git a/lib/class/query.class.php b/lib/class/query.class.php
index d586d726..857adf61 100644
--- a/lib/class/query.class.php
+++ b/lib/class/query.class.php
@@ -225,12 +225,65 @@ class Query {
$db_results = Dba::write($sql);
}
+ /**
+ * _serialize
+ *
+ * Attempts to produce a more compact representation for large result
+ * sets by collapsing ranges.
+ */
private static function _serialize($data) {
- return serialize($data);
+ if (count($data) > 1000) {
+ sort($data);
+ $last = -17;
+ $in_range = false;
+ $idx = -1;
+ $cooked = array();
+ foreach ($data as $id) {
+ if ($id == ($last + 1)) {
+ if ($in_range) {
+ $cooked[$idx][1] = $id;
+ }
+ else {
+ $in_range = true;
+ $cooked[$idx] = array($last, $id);
+ }
+ }
+ else {
+ $in_range = false;
+ $idx++;
+ $cooked[$idx] = $id;
+ }
+ $last = $id;
+ }
+ $data = json_encode($cooked);
+ debug_event('Query', 'cooked serialize length: ' . strlen($data), 5);
+ }
+ else {
+ $data = json_encode($data);
+ }
+
+ return $data;
}
+ /*
+ * _unserialize
+ *
+ * Reverses serialization.
+ */
private static function _unserialize($data) {
- return unserialize($data);
+ $raw = array();
+ $cooked = json_decode($data);
+ foreach ($cooked as $grain) {
+ if (is_array($grain)) {
+ foreach(range($grain[0], $grain[1]) as $id) {
+ $raw[] = $id;
+ }
+ }
+ else {
+ $raw[] = $grain;
+ }
+ }
+ return $raw;
}
/**