Plugin Directory

Changeset 2771905


Ignore:
Timestamp:
08/18/2022 04:33:40 AM (4 years ago)
Author:
winrid
Message:

3.12.5 - Performance improvements for the initial sync.

Location:
fastcomments
Files:
40 added
5 edited

Legend:

Unmodified
Added
Removed
  • fastcomments/trunk/README.txt

    r2768101 r2771905  
    44Requires at least: 4.6
    55Tested up to: 6.0
    6 Stable tag: 3.12.4
     6Stable tag: 3.12.5
    77Requires PHP: 5.2.5
    88License: GPLv2 or later
     
    48484. Activate the Plugin
    49495. Click FastComments in the left admin panel.
    50 6. Follow the steps to setup and connect your WordPress installation to our servers. Don't worry, it's just a couple clicks.
     506. Follow the steps to set up and connect your WordPress installation to our servers. Don't worry, it's just a couple clicks.
    5151
    5252You can expect the sync to take several minutes if you have tens of thousands of comments or more.
     
    7373= Can I switch back to default WordPress comments? =
    7474
    75 By default FastComments keeps your WordPress installation in sync with our servers. We send very small updates, at most once a minute if needed, for any new comments.
     75By default, FastComments keeps your WordPress installation in sync with our servers. We send very small updates, at most once a minute if needed, for any new comments.
    7676
    7777Simply cancel your account and deactivate the plugin to switch back, but we don't think you'll want to!
     
    8787
    8888== Changelog ==
     89
     90= 3.12.5 =
     91* Performance improvements for the initial sync.
    8992
    9093= 3.12.4 =
  • fastcomments/trunk/core/FastCommentsIntegrationCore.php

    r2752858 r2771905  
    166166        $token = $this->getSettingValue('fastcomments_token');
    167167        if ($token) {
    168             $lastFetchDate = $this->getSettingValue('fastcomments_stream_last_fetch_timestamp');
     168            $lastFetchDate = $this->getSettingValue('fastcomments_stream_last_fetch_timestamp', true);
    169169            $lastFetchDateToSend = $lastFetchDate ? $lastFetchDate : 0;
    170170            $this->log('debug', "Polling next commands for fromDateTime=[$lastFetchDateToSend].");
     
    198198    public function commandFetchEvents($token) {
    199199        $this->log('debug', "BEGIN commandFetchEvents");
    200         $fromDateTime = $this->getSettingValue('fastcomments_stream_last_fetch_timestamp');
     200        $fromDateTime = $this->getSettingValue('fastcomments_stream_last_fetch_timestamp', true);
    201201        $hasMore = true;
    202202        $startedAt = time();
     
    214214                }
    215215                $hasMore = !!$response->hasMore;
    216                 $this->setSettingValue('fastcomments_stream_last_fetch_timestamp', $fromDateTime);
     216                $this->setSettingValue('fastcomments_stream_last_fetch_timestamp', $fromDateTime, false);
    217217            } else {
    218218                $this->log('error', "Failed to get events: {$rawIntegrationEventsResponse}");
     
    225225    private function canAckLock($name, $windowSeconds) {
    226226        $settingName = $this->getLockName($name);
    227         $lastTime = $this->getSettingValue($settingName);
     227        $this->log('debug', "BEGIN canAckLock $settingName with window $windowSeconds");
     228        $lastTime = $this->getSettingValue($settingName, true);
     229        if (!$lastTime) {
     230            $this->log('debug', "END canAckLock $settingName last lock time $lastTime. Got lock=[1]");
     231            return true;
     232        }
    228233        $now = time();
    229         if ($lastTime && $now - $lastTime < $windowSeconds) {
    230             return false;
    231         }
    232         $this->setSettingValue($settingName, $now);
    233         return true;
     234        $delta = $now - ((int) ($lastTime));
     235        $gotLock = $delta >= $windowSeconds;
     236        $this->log('debug', "END canAckLock $settingName last lock time $lastTime. Delta=[$delta] Got lock=[$gotLock]");
     237        return $gotLock;
    234238    }
    235239
    236240    private function tryAckLock($name, $windowSeconds) {
     241        $settingName = $this->getLockName($name);
     242        $this->log('debug', "BEGIN tryAckLock $settingName with window $windowSeconds");
    237243        $secondsRemaining = 5;
    238244        $retryInterval = 1;
     
    240246        while (!$gotLock && $secondsRemaining > 0) {
    241247            $gotLock = $this->canAckLock($name, $windowSeconds);
     248            $this->log('debug', "PROGRESS tryAckLock $settingName with window $windowSeconds in loop. Got lock=[$gotLock]");
    242249            if (!$gotLock) {
    243250                $secondsRemaining = $secondsRemaining - $retryInterval;
     
    245252            }
    246253        }
     254        if ($gotLock) {
     255            $now = time();
     256            $this->log('debug', "PROGRESS tryAckLock acquiring lock $settingName for now=[$now]");
     257            $this->setSettingValue($settingName, $now, false);
     258        }
     259        $this->log('debug', "END tryAckLock $settingName Got lock=[$gotLock]");
    247260        return $gotLock;
    248261    }
     
    250263    private function resetLock($name, $windowSeconds) {
    251264        $settingName = $this->getLockName($name);
    252         $this->setSettingValue($settingName, time() + $windowSeconds);
     265        $attemptedNewValue = time() + $windowSeconds;
     266        $this->log('debug', "BEGIN resetLock $settingName for window $windowSeconds (setting to=[$attemptedNewValue])");
     267        $this->setSettingValue($settingName, $attemptedNewValue, false);
     268        $newValue = $this->getSettingValue($settingName, true);
     269        $this->log('debug', "END resetLock $settingName for window $windowSeconds. New value=[$newValue]");
    253270    }
    254271
     
    259276    private function clearLock($name) {
    260277        $settingName = $this->getLockName($name);
    261         $this->setSettingValue($settingName, null);
     278        $this->log('debug', "BEGIN clearLock $settingName");
     279        $this->setSettingValue($settingName, null, false);
     280        $wasCleared = $this->getSettingValue($settingName, true);
     281        $this->log('debug', "END clearLock $settingName. New value=[$wasCleared]");
     282    }
     283
     284    public function removeSendCommentsLock() {
     285        $this->clearLock("commandSendComments");
    262286    }
    263287
     
    273297            return 'LOCK_WAITING';
    274298        }
    275         $lastSendDate = $this->getSettingValue('fastcomments_stream_last_send_timestamp');
    276         $lastSentId = $this->getSettingValue('fastcomments_stream_last_send_id');
     299        $lastSendDate = $this->getSettingValue('fastcomments_stream_last_send_timestamp', true);
     300        $lastSentId = $this->getSettingValue('fastcomments_stream_last_send_id', true);
    277301        $commentCount = $this->getCommentCount($lastSentId ? $lastSentId : -1);
    278302        if ($commentCount == 0) {
     
    329353                                    $countRemaining = $countRemainingIfSuccessful;
    330354                                    $fromDateTime = $lastCommentFromDateTime;
    331                                     $this->setSettingValue('fastcomments_stream_last_send_timestamp', $fromDateTime);
    332                                     $this->setSettingValue('fastcomments_stream_last_send_id', $lastComment['externalId']);
     355                                    $this->setSettingValue('fastcomments_stream_last_send_timestamp', $fromDateTime, false);
     356                                    $this->setSettingValue('fastcomments_stream_last_send_id', $lastComment['externalId'], false);
    333357                                    if ($countRemaining <= 0) {
    334358                                        $this->setSetupDone();
     
    358382            $this->log('error', "Failed to get comments to send: status=[$status] comments=[$comments]");
    359383        }
    360         $this->resetLock("commandSendComments", 1); // Instead of calling clearLock, prevent race condition on page refresh during setup where same chunk can get submitted twice. Not the worst thing in the world but looks weird to user.
     384        // setting the lock to 1 second out causes each chunk upload to wait 59 seconds... so let's always clear it
     385        // we fixed issues with lock state being cached, and added a de-dupe mechanism in the backend to detect duplicate chunks, so race conditions should not be an issue.
     386        $this->clearLock("commandSendComments");
    361387        $this->log('debug', 'Done sending comments');
    362388        return $countSynced;
  • fastcomments/trunk/core/FastCommentsWordPressIntegration.php

    r2744374 r2771905  
    152152    }
    153153
    154     public function getSettingValue($settingName) {
     154    public function getSettingValue($settingName, $fromDB = false) {
     155        if ($fromDB) {
     156            wp_cache_delete($settingName, 'options');
     157        }
    155158        return get_option($settingName);
    156159    }
    157160
    158     public function setSettingValue($settingName, $settingValue) {
    159         update_option($settingName, $settingValue);
     161    public function setSettingValue($settingName, $settingValue, $autoload = true) {
     162        if ($settingValue === null) {
     163            delete_option($settingName);
     164            wp_cache_delete($settingName, 'options');
     165        } else {
     166            update_option($settingName, $settingValue);
     167        }
    160168    }
    161169
  • fastcomments/trunk/fastcomments-wordpress-plugin.php

    r2768103 r2771905  
    44Plugin URI: https://fastcomments.com
    55Description: Live Comments, Fast. A comment system that will delight your users and developers.
    6 Version: 3.12.4
     6Version: 3.12.5
    77Author: winrid @ FastComments
    88License: GPL-2.0+
     
    1414}
    1515
    16 $FASTCOMMENTS_VERSION = 3.124;
     16$FASTCOMMENTS_VERSION = 3.125;
    1717
    1818require_once plugin_dir_path(__FILE__) . 'admin/fastcomments-admin.php';
  • fastcomments/trunk/uninstall.php

    r2744374 r2771905  
    1010require_once plugin_dir_path(__FILE__) . 'core/FastCommentsWordPressIntegration.php';
    1111
     12$fastcomments = new FastCommentsWordPressIntegration();
     13$fastcomments->removeSendCommentsLock();
     14
    1215delete_option( 'fastcomments_tenant_id' );
    1316delete_option( 'fastcomments_connection_token' );
     
    1922delete_option( 'fastcomments_cdn' );
    2023
    21 $fastcomments = new FastCommentsWordPressIntegration();
     24
    2225$fastcomments->deactivate();
Note: See TracChangeset for help on using the changeset viewer.