|
@@ -32,8 +32,8 @@ if (empty($validIds)) {
|
|
|
sort($validIds);
|
|
sort($validIds);
|
|
|
$idsStr = implode(',', $validIds);
|
|
$idsStr = implode(',', $validIds);
|
|
|
|
|
|
|
|
-// Generate deterministic hash from the sorted activity IDs
|
|
|
|
|
-$hash = hash('sha256', $idsStr);
|
|
|
|
|
|
|
+// Generate deterministic 5-character hash from the sorted activity IDs
|
|
|
|
|
+$hash = substr(hash('sha256', $idsStr), 0, 5);
|
|
|
|
|
|
|
|
// Check if this exact selection already has a hash stored
|
|
// Check if this exact selection already has a hash stored
|
|
|
$stmt = $pdo->prepare("SELECT hash FROM selection_hashes WHERE activity_ids = ?");
|
|
$stmt = $pdo->prepare("SELECT hash FROM selection_hashes WHERE activity_ids = ?");
|
|
@@ -41,7 +41,11 @@ $stmt->execute([$idsStr]);
|
|
|
$existing = $stmt->fetchColumn();
|
|
$existing = $stmt->fetchColumn();
|
|
|
|
|
|
|
|
if ($existing) {
|
|
if ($existing) {
|
|
|
- $hash = $existing;
|
|
|
|
|
|
|
+ if ($existing !== $hash) {
|
|
|
|
|
+ // Overwrite old (long) hash with the new short hash
|
|
|
|
|
+ $stmt = $pdo->prepare("UPDATE selection_hashes SET hash = ? WHERE activity_ids = ?");
|
|
|
|
|
+ $stmt->execute([$hash, $idsStr]);
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
// Store new hash
|
|
// Store new hash
|
|
|
$stmt = $pdo->prepare("INSERT INTO selection_hashes (hash, activity_ids) VALUES (?, ?)");
|
|
$stmt = $pdo->prepare("INSERT INTO selection_hashes (hash, activity_ids) VALUES (?, ?)");
|