Skip to content

Commit

Permalink
Eliminate lock timeout filter
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwatkins0 committed Nov 23, 2020
1 parent 8ea22d6 commit 13917b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
23 changes: 8 additions & 15 deletions src/Validation/URLValidationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ final class URLValidationProvider {
*/
const LOCK_KEY = 'amp_validation_locked';

/**
* The length of time to keep the lock in place if a process fails to unlock.
*
* @var int
*/
const LOCK_TIMEOUT = 5 * MINUTE_IN_SECONDS;

/**
* The total number of validation errors, regardless of whether they were accepted.
*
Expand Down Expand Up @@ -88,21 +95,7 @@ public function is_locked() {
$lock_time = (int) get_option( self::LOCK_KEY, 0 );

// It's locked if the difference between the lock time and the current time is less than the lockout time.
return time() - $lock_time < $this->get_lock_timeout();
}

/**
* Provides the length of time, in seconds, to lock validation when this runs.
*
* @return int
*/
private function get_lock_timeout() {
/**
* Filters the length of time to lock URL validation when a process starts.
*
* @param int $timeout Time in seconds. Default 300 seconds.
*/
return apply_filters( 'amp_validation_lock_timeout', 5 * MINUTE_IN_SECONDS );
return time() - $lock_time < self::LOCK_TIMEOUT;
}

/**
Expand Down
1 change: 0 additions & 1 deletion tests/php/src/Validation/URLValidationProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public function test_get_url_validation() {
* @covers ::lock()
* @covers ::unlock()
* @covers ::is_locked()
* @covers ::get_lock_timeout()
* @covers ::with_lock()
*/
public function test_locking() {
Expand Down

0 comments on commit 13917b3

Please sign in to comment.