summaryrefslogtreecommitdiff
path: root/modules/comment.module
diff options
context:
space:
mode:
authorSteven Wittens <steven@10.no-reply.drupal.org>2006-02-09 08:33:36 +0000
committerSteven Wittens <steven@10.no-reply.drupal.org>2006-02-09 08:33:36 +0000
commitc9a19e3084d3d9932dc83f9f61126c7ac5d6e366 (patch)
treeddfd9d8a76e3b1db6556089a0cc4a2ad8ab14679 /modules/comment.module
parent0d89f29a3fd72e328346eb3e06dbb4b4b99bc403 (diff)
downloadbrdo-c9a19e3084d3d9932dc83f9f61126c7ac5d6e366.tar.gz
brdo-c9a19e3084d3d9932dc83f9f61126c7ac5d6e366.tar.bz2
- #48239: Comment thread coding inefficient
Diffstat (limited to 'modules/comment.module')
-rw-r--r--modules/comment.module60
1 files changed, 29 insertions, 31 deletions
diff --git a/modules/comment.module b/modules/comment.module
index bc498b193..b760b82a4 100644
--- a/modules/comment.module
+++ b/modules/comment.module
@@ -573,25 +573,8 @@ function comment_save($edit) {
// Strip the "/" from the end of the thread.
$max = rtrim($max, '/');
- // Next, we increase this value by one. Note that we can't
- // use 1, 2, 3, ... 9, 10, 11 because we order by string and
- // 10 would be right after 1. We use 1, 2, 3, ..., 9, 91,
- // 92, 93, ... instead. Ugly but fast.
- $decimals = (string) substr($max, 0, strlen($max) - 1);
- $units = substr($max, -1, 1);
- if ($units) {
- $units++;
- }
- else {
- $units = 1;
- }
-
- if ($units == 10) {
- $units = '90';
- }
-
// Finally, build the thread field for this new comment.
- $thread = $decimals . $units .'/';
+ $thread = int2vancode(vancode2int($max) + 1) .'/';
}
else {
// This is comment with a parent comment: we increase
@@ -608,7 +591,7 @@ function comment_save($edit) {
if ($max == '') {
// First child of this parent.
- $thread = $parent->thread .'.1/';
+ $thread = $parent->thread .'.'. int2vancode(0) .'/';
}
else {
// Strip the "/" at the end of the thread.
@@ -619,19 +602,8 @@ function comment_save($edit) {
$parent_depth = count(explode('.', $parent->thread));
$last = $parts[$parent_depth];
- // Next, we increase this value by one. Note that we can't
- // use 1, 2, 3, ... 9, 10, 11 because we order by string and
- // 10 would be right after 1. We use 1, 2, 3, ..., 9, 91,
- // 92, 93, ... instead. Ugly but fast.
- $decimals = (string)substr($last, 0, strlen($last) - 1);
- $units = substr($last, -1, 1);
- $units++;
- if ($units == 10) {
- $units = '90';
- }
-
// Finally, build the thread field for this new comment.
- $thread = $parent->thread .'.'. $decimals . $units .'/';
+ $thread = $parent->thread .'.'. int2vancode(vancode2int($last) + 1) .'/';
}
}
@@ -1717,3 +1689,29 @@ function comment_invoke_comment(&$comment, $op) {
}
return $return;
}
+
+/**
+ * Generate vancode.
+ *
+ * Consists of a leading character indicating length, followed by N digits
+ * with a numerical value in base 36. Vancodes can be sorted as strings
+ * without messing up numerical order.
+ *
+ * It goes:
+ * 00, 01, 02, ..., 0y, 0z,
+ * 110, 111, ... , 1zy, 1zz,
+ * 2100, 2101, ..., 2zzy, 2zzz,
+ * 31000, 31001, ...
+ */
+function int2vancode($i = 0) {
+ $num = base_convert((int)$i, 10, 36);
+ $length = strlen($num);
+ return chr($length + ord('0') - 1) . $num;
+}
+
+/**
+ * Decode vancode back to an integer.
+ */
+function vancode2int($c = '00') {
+ return base_convert(substr($c, 1), 36, 10);
+}