Changeset 2588650
- Timestamp:
- 08/25/2021 03:45:53 PM (5 years ago)
- Location:
- fastcomments
- Files:
-
- 34 added
- 5 edited
-
tags/3.9.9 (added)
-
tags/3.9.9/.gitignore (added)
-
tags/3.9.9/LICENSE (added)
-
tags/3.9.9/README.md (added)
-
tags/3.9.9/README.txt (added)
-
tags/3.9.9/admin (added)
-
tags/3.9.9/admin/fastcomments-admin-setup-view.js (added)
-
tags/3.9.9/admin/fastcomments-admin-setup-view.php (added)
-
tags/3.9.9/admin/fastcomments-admin-sso-view.css (added)
-
tags/3.9.9/admin/fastcomments-admin-sso-view.js (added)
-
tags/3.9.9/admin/fastcomments-admin-sso-view.php (added)
-
tags/3.9.9/admin/fastcomments-admin-support-view.php (added)
-
tags/3.9.9/admin/fastcomments-admin-view.php (added)
-
tags/3.9.9/admin/fastcomments-admin.css (added)
-
tags/3.9.9/admin/fastcomments-admin.php (added)
-
tags/3.9.9/admin/images (added)
-
tags/3.9.9/admin/images/api.png (added)
-
tags/3.9.9/admin/images/crown.png (added)
-
tags/3.9.9/admin/images/css.png (added)
-
tags/3.9.9/admin/images/debugging.png (added)
-
tags/3.9.9/admin/images/download.png (added)
-
tags/3.9.9/admin/images/home.png (added)
-
tags/3.9.9/admin/images/logo-50.png (added)
-
tags/3.9.9/admin/images/logo.png (added)
-
tags/3.9.9/admin/images/support.png (added)
-
tags/3.9.9/admin/images/sync.png (added)
-
tags/3.9.9/core (added)
-
tags/3.9.9/core/FastCommentsIntegrationCore.php (added)
-
tags/3.9.9/core/FastCommentsWordPressIntegration.php (added)
-
tags/3.9.9/fastcomments-wordpress-plugin.php (added)
-
tags/3.9.9/public (added)
-
tags/3.9.9/public/fastcomments-public.php (added)
-
tags/3.9.9/public/fastcomments-widget-view.php (added)
-
tags/3.9.9/uninstall.php (added)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/core/FastCommentsIntegrationCore.php (modified) (7 diffs)
-
trunk/core/FastCommentsWordPressIntegration.php (modified) (3 diffs)
-
trunk/fastcomments-wordpress-plugin.php (modified) (2 diffs)
-
trunk/public/fastcomments-public.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
fastcomments/trunk/README.txt
r2586216 r2588650 4 4 Requires at least: 4.6 5 5 Tested up to: 5.8 6 Stable tag: 3.9. 86 Stable tag: 3.9.9 7 7 Requires PHP: 5.2.4 8 8 License: GPLv2 or later … … 84 84 85 85 == Changelog == 86 87 = 3.9.9 = 88 * Sync now supports sites more comments for a more reliable migration. They do not have to fit in memory during sync. 86 89 87 90 = 3.9.8 = -
fastcomments/trunk/core/FastCommentsIntegrationCore.php
r2586120 r2588650 38 38 public abstract function handleEvents($events); 39 39 40 public abstract function getCommentCount($ startFromDateTime);41 42 public abstract function getComments($ startFromDateTime);40 public abstract function getCommentCount($afterId); 41 42 public abstract function getComments($afterId); 43 43 44 44 public function base64Encode($stringValue) { … … 217 217 } 218 218 219 private function canAckLock($name, $window ) {219 private function canAckLock($name, $windowSeconds) { 220 220 $settingName = $this->getLockName($name); 221 221 $lastTime = $this->getSettingValue($settingName); 222 222 $now = time(); 223 if ($lastTime && $now - $lastTime < $window ) {223 if ($lastTime && $now - $lastTime < $windowSeconds) { 224 224 return false; 225 225 } … … 238 238 239 239 public function commandSendComments($token) { 240 /** 241 * Fetch 500 comments a time from the DB. 242 * Split them up into chunks of 100. 243 * If the server complains the payload is too large, recursively split the chunk by / 10. 244 */ 240 245 $this->log('debug', 'Starting to send comments'); 241 if (!$this->canAckLock("commandSendComments", 3000)) {246 if (!$this->canAckLock("commandSendComments", 60)) { 242 247 $this->log('debug', 'Can not send right now, waiting for previous attempt to finish.'); 243 248 return; 244 249 } 245 250 $lastSendDate = $this->getSettingValue('fastcomments_stream_last_send_timestamp'); 246 $ startedAt = time();247 $ hasMore = true;248 if ($ this->getCommentCount(0)== 0) {249 $this->log('debug', 'No comments to send. Telling server.');251 $lastSentId = $this->getSettingValue('fastcomments_stream_last_send_id'); 252 $commentCount = $this->getCommentCount($lastSentId ? $lastSentId : 0); 253 if ($commentCount == 0) { 254 $this->log('debug', "No comments to send. Telling server. lastSendDate=[$lastSendDate] lastSentId=[$lastSentId]"); 250 255 $requestBody = json_encode( 251 256 array( … … 259 264 return; 260 265 } 261 // while ($hasMore && time() - $startedAt < 30 * 1000) {262 266 $this->log('debug', 'Send comments command loop...'); 263 $getCommentsResponse = $this->getComments($lastSen dDate ? $lastSendDate: 0);267 $getCommentsResponse = $this->getComments($lastSentId ? $lastSentId : 0); 264 268 if ($getCommentsResponse['status'] === 'success') { 265 269 $count = count($getCommentsResponse['comments']); 266 $hasMore = $getCommentsResponse['hasMore']; 267 $this->log('info', "Got comments to send count=[$count] hasMore=[$hasMore]"); 268 $countRemaining = $getCommentsResponse['comments'] ? count($getCommentsResponse['comments']) : 0; 270 $this->log('info', "Got comments to send count=[$count] from totalCount=[$commentCount] lastSendDate=[$lastSendDate] lastSentId=[$lastSentId]"); 271 $countRemaining = $commentCount; 269 272 $chunkSize = 100; 270 273 if ($countRemaining > 0) { … … 277 280 while ($chunkAttemptsRemaining > 0) { 278 281 foreach ($dynamicChunks as $dynamicChunk) { 279 $lastCommentFromDateTime = strtotime($dynamicChunk[count($dynamicChunk) - 1]['date']) * 1000; 282 $lastComment = $dynamicChunk[count($dynamicChunk) - 1]; 283 $lastCommentFromDateTime = strtotime($lastComment['date']) * 1000; 280 284 $countRemainingIfSuccessful = $countRemaining - count($dynamicChunk); 281 285 $requestBody = json_encode( … … 292 296 $countRemaining = $countRemainingIfSuccessful; 293 297 $fromDateTime = $lastCommentFromDateTime; 294 $lastSendDate = $fromDateTime;295 298 $this->setSettingValue('fastcomments_stream_last_send_timestamp', $fromDateTime); 299 $this->setSettingValue('fastcomments_stream_last_send_id', $lastComment['externalId']); 296 300 if ($countRemaining <= 0) { 297 301 $this->setSetupDone(); 298 // break;299 302 } 300 303 } … … 311 314 } else { 312 315 $this->setSetupDone(); 313 // break;314 316 } 315 317 } else { 316 318 $status = $getCommentsResponse['status']; 317 319 $comments = $getCommentsResponse['comments']; 318 $debugHasMore = $getCommentsResponse['hasMore']; 319 $this->log('error', "Failed to get comments to send: status=[$status] comments=[$comments] hasMore=[$debugHasMore]}"); 320 // break; 321 } 322 // } 320 $this->log('error', "Failed to get comments to send: status=[$status] comments=[$comments]"); 321 } 322 $this->clearLock("commandSendComments"); 323 323 $this->log('debug', 'Done sending comments'); 324 324 } -
fastcomments/trunk/core/FastCommentsWordPressIntegration.php
r2586216 r2588650 74 74 delete_option('fastcomments_stream_last_fetch_timestamp'); 75 75 delete_option('fastcomments_stream_last_send_timestamp'); 76 delete_option('fastcomments_stream_last_send_id'); 76 77 delete_option('fastcomments_comment_sent_count'); 77 78 … … 326 327 if ($wp_comment) { 327 328 wp_update_comment($wp_comment); 328 add_comment_meta($wp_comment ->comment_ID, 'fastcomments_id', $eventData->comment->_id, true);329 add_comment_meta($wp_comment['comment_ID'], 'fastcomments_id', $eventData->comment->_id, true); 329 330 } else { 330 331 $this->log('debug', "Skipping sync of $fcId - is not from the WP integration."); … … 373 374 } 374 375 375 public function getCommentCount($startFromDateTime) { 376 // if (isset($startFromDateTime)) { 377 // $args = array( 378 // 'date_query' => array( 379 // 'after' => date('c', $startFromDateTime ? $startFromDateTime / 1000 : 0) 380 // ), 381 // 'count' => true 382 // ); 383 // $wp_comments_count = get_comments($args); 384 // return $wp_comments_count; 385 // } else { 386 $count_result = wp_count_comments(); 387 return $count_result ? $count_result->total_comments : 0; 388 // } 389 } 390 391 public function getComments($startFromDateTime) { 392 // $limit = 100; 393 $args = array( 394 // 'number' => $limit + 1, 395 'date_query' => array( 396 'after' => date('c', $startFromDateTime ? $startFromDateTime / 1000 : 0), 397 'inclusive' => true 398 ), 399 'orderby' => array('comment_date', 'comment_ID'), 400 'order' => 'ASC' 401 ); 402 $wp_comments = get_comments($args); 403 // $has_more = count($wp_comments) > $limit; 404 $has_more = false; 376 private function getCommentQueryWhere($afterId) { 377 // This query ensures a stable sort for pagination and allows us to paginate while not seeing the same comment twice. 378 return "comment_ID > $afterId"; 379 } 380 381 public function getCommentCount($afterId) { 382 $where = $this->getCommentQueryWhere($afterId); 383 global $wpdb; 384 $sql = "SELECT count(*) FROM $wpdb->comments WHERE $where"; 385 return $wpdb->get_var($sql); 386 } 387 388 public function getComments($afterId) { 389 $where = $this->getCommentQueryWhere($afterId); 390 global $wpdb; 391 $sql = "SELECT * FROM $wpdb->comments WHERE $where ORDER BY comment_ID ASC LIMIT 100"; 392 $query_result = $wpdb->get_results($sql); 405 393 $fc_comments = array(); 406 // for ($i = 0; $i < min(count($wp_comments), $limit); $i++) { 407 for ($i = 0; $i < count($wp_comments); $i++) { 408 array_push($fc_comments, $this->wp_to_fc_comment($wp_comments[$i])); 394 foreach ($query_result as $wp_comment_row) { 395 $wp_comment = get_comment($wp_comment_row); 396 if ($wp_comment) { 397 array_push($fc_comments, $this->wp_to_fc_comment($wp_comment)); 398 } else { 399 $this->log('warn', "Comment $wp_comment_row->comment_ID was not found from WP after fetching from raw query."); 400 } 409 401 } 410 402 return array( 411 403 "status" => "success", 412 "comments" => $fc_comments, 413 "hasMore" => $has_more 404 "comments" => $fc_comments 414 405 ); 415 406 } 416 407 } 408 -
fastcomments/trunk/fastcomments-wordpress-plugin.php
r2586216 r2588650 4 4 Plugin URI: https://fastcomments.com 5 5 Description: Live Comments, Fast. A comment system that will delight your users and developers. 6 Version: 3.9. 86 Version: 3.9.9 7 7 Author: winrid @ FastComments 8 8 License: GPL-2.0+ … … 14 14 } 15 15 16 $FASTCOMMENTS_VERSION = 3.9 8;16 $FASTCOMMENTS_VERSION = 3.99; 17 17 18 18 require_once plugin_dir_path(__FILE__) . 'admin/fastcomments-admin.php'; -
fastcomments/trunk/public/fastcomments-public.php
r2584331 r2588650 95 95 $sso_user['avatar'] = get_avatar_url($wp_user->ID, 95); 96 96 $sso_user['optedInNotifications'] = true; 97 // TODO pass isAdmin/isModerator flags 97 98 } 98 99
Note: See TracChangeset
for help on using the changeset viewer.