Plugin Directory

Changeset 2586120


Ignore:
Timestamp:
08/20/2021 05:23:13 PM (5 years ago)
Author:
winrid
Message:

3.9.7 - Dynamically adjust request size on initial sync to ensure all comments are migrated while still keeping the initial sync fast.

Location:
fastcomments
Files:
34 added
3 edited

Legend:

Unmodified
Added
Removed
  • fastcomments/trunk/README.txt

    r2585075 r2586120  
    44Requires at least: 4.6
    55Tested up to: 5.8
    6 Stable tag: 3.9.6
     6Stable tag: 3.9.7
    77Requires PHP: 5.2.4
    88License: GPLv2 or later
     
    8484
    8585== Changelog ==
     86
     87= 3.9.7 =
     88* Dynamically adjust request size on initial sync to ensure all comments are migrated while still keeping the initial sync fast.
    8689
    8790= 3.9.6 =
  • fastcomments/trunk/core/FastCommentsIntegrationCore.php

    r2577475 r2586120  
    260260        }
    261261//        while ($hasMore && time() - $startedAt < 30 * 1000) {
    262             $this->log('debug', 'Send comments command loop...');
    263             $getCommentsResponse = $this->getComments($lastSendDate ? $lastSendDate : 0);
    264             if ($getCommentsResponse['status'] === 'success') {
    265                 $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;
    269                 if ($countRemaining > 0) {
    270                     $commentChunks = array_chunk($getCommentsResponse['comments'], 100);
    271                     foreach ($commentChunks as $chunk) {
    272                         $lastCommentFromDateTime = strtotime($chunk[count($chunk) - 1]['date']) * 1000;
    273                         $countRemaining -= count($chunk);
    274                         $requestBody = json_encode(
    275                             array(
    276                                 "countRemaining" => $countRemaining,
    277                                 "comments" => $chunk
    278                             )
    279                         );
    280                         $httpResponse = $this->makeHTTPRequest('POST', "$this->baseUrl/comments?token=$token", $requestBody);
    281                         $this->log('debug', "Got POST /comments response status code=[$httpResponse->responseStatusCode]");
    282                         $response = json_decode($httpResponse->responseBody);
    283 //                        if ($response->status === 'success') {
    284                             $fromDateTime = $lastCommentFromDateTime;
    285                             $lastSendDate = $fromDateTime;
    286                             $this->setSettingValue('fastcomments_stream_last_send_timestamp', $fromDateTime);
    287                             if ($countRemaining <= 0) {
    288                                 $this->setSetupDone();
    289                                 break;
     262        $this->log('debug', 'Send comments command loop...');
     263        $getCommentsResponse = $this->getComments($lastSendDate ? $lastSendDate : 0);
     264        if ($getCommentsResponse['status'] === 'success') {
     265            $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;
     269            $chunkSize = 100;
     270            if ($countRemaining > 0) {
     271                $commentChunks = array_chunk($getCommentsResponse['comments'], $chunkSize);
     272                foreach ($commentChunks as $chunk) {
     273                    // for this chunk, attempt to send the whole thing. If it fails, split it up.
     274                    $chunkAttemptsRemaining = 5;
     275                    $dynamicChunkSize = $chunkSize;
     276                    $dynamicChunks = array($chunk);
     277                    while ($chunkAttemptsRemaining > 0) {
     278                        foreach ($dynamicChunks as $dynamicChunk) {
     279                            $lastCommentFromDateTime = strtotime($dynamicChunk[count($dynamicChunk) - 1]['date']) * 1000;
     280                            $countRemainingIfSuccessful = $countRemaining - count($dynamicChunk);
     281                            $requestBody = json_encode(
     282                                array(
     283                                    "countRemaining" => $countRemainingIfSuccessful,
     284                                    "comments" => $dynamicChunk
     285                                )
     286                            );
     287                            $httpResponse = $this->makeHTTPRequest('POST', "$this->baseUrl/comments?token=$token", $requestBody);
     288                            $this->log('debug', "Got POST /comments response status code=[$httpResponse->responseStatusCode] and chunk size $dynamicChunkSize");
     289                            if ($httpResponse->responseStatusCode === 200) {
     290                                $response = json_decode($httpResponse->responseBody);
     291                                if ($response->status === 'success') {
     292                                    $countRemaining = $countRemainingIfSuccessful;
     293                                    $fromDateTime = $lastCommentFromDateTime;
     294                                    $lastSendDate = $fromDateTime;
     295                                    $this->setSettingValue('fastcomments_stream_last_send_timestamp', $fromDateTime);
     296                                    if ($countRemaining <= 0) {
     297                                        $this->setSetupDone();
     298//                                        break;
     299                                    }
     300                                }
     301                                $chunkAttemptsRemaining = 0; // done
     302                            } else if ($httpResponse->responseStatusCode === 413 && $dynamicChunkSize > 1) {
     303                                $this->log('debug', "$dynamicChunkSize too big, splitting.");
     304                                $dynamicChunks = array_chunk($chunk, max((int)($dynamicChunkSize / 10), 1));
     305                                break; // break out of the dynamic chunks loop and run it again
    290306                            }
    291 //                        }
     307                        }
     308                        $chunkAttemptsRemaining--;
    292309                    }
    293                 } else {
    294                     $this->setSetupDone();
    295 //                    break;
    296310                }
    297311            } else {
    298                 $status = $getCommentsResponse['status'];
    299                 $comments = $getCommentsResponse['comments'];
    300                 $debugHasMore = $getCommentsResponse['hasMore'];
    301                 $this->log('error', "Failed to get comments to send: status=[$status] comments=[$comments] hasMore=[$debugHasMore]}");
     312                $this->setSetupDone();
     313//                    break;
     314            }
     315        } else {
     316            $status = $getCommentsResponse['status'];
     317            $comments = $getCommentsResponse['comments'];
     318            $debugHasMore = $getCommentsResponse['hasMore'];
     319            $this->log('error', "Failed to get comments to send: status=[$status] comments=[$comments] hasMore=[$debugHasMore]}");
    302320//                break;
    303             }
     321        }
    304322//        }
    305323        $this->log('debug', 'Done sending comments');
  • fastcomments/trunk/fastcomments-wordpress-plugin.php

    r2585075 r2586120  
    44Plugin URI: https://fastcomments.com
    55Description: Live Comments, Fast. A comment system that will delight your users and developers.
    6 Version: 3.9.6
     6Version: 3.9.7
    77Author: winrid @ FastComments
    88License: GPL-2.0+
     
    1414}
    1515
    16 $FASTCOMMENTS_VERSION = 3.96;
     16$FASTCOMMENTS_VERSION = 3.97;
    1717
    1818require_once plugin_dir_path(__FILE__) . 'admin/fastcomments-admin.php';
Note: See TracChangeset for help on using the changeset viewer.