You are here

public function AcquiaPurgeService::deduplicate in Acquia Purge 7

Prevent duplicate path queuing and purging.

Our queue is database backed and if we would query every path before it ends up in the queue, the cost would become too expensive. This helper however, maintains breadcrumb lists of the paths it was given and returns FALSE for new items and TRUE for old items. Items are theoretically kept till the queue is emptied.

If the site has 'acquia_purge_memcache' set to TRUE, the implementation will use the state storage mechanism in addition to the static variables, which means that data will persist between requests. With the file-based state storage, this would result in massive IO activity so less accurate deduplication is acceptable.

@warning Duplicated paths can still end up in the queue, especially when not using the 'acquia_purge_memcache' setting.

Parameters

string $path: The Drupal path (for example: '<front>', 'user/1' or a alias).

string $list: (optional) Two breadcrumb lists are kept, 'queued' for preventative deduplication and 'purged' for keeping a post-purge track record.

int $l: (optional) The $l parameter stands for 'limit' and represents the amount of items in a list to be crossed before it gets emptied.

Return value

true|false TRUE when the path is in the given list, FALSE when not.

3 calls to AcquiaPurgeService::deduplicate()
AcquiaPurgeService::addPath in lib/AcquiaPurgeService.php
Queue a single path.
AcquiaPurgeService::addPaths in lib/AcquiaPurgeService.php
Queue several paths.
AcquiaPurgeService::process in lib/AcquiaPurgeService.php
Process as many items from the queue as the runtime capacity allows.

File

lib/AcquiaPurgeService.php, line 238
Contains AcquiaPurgeService.

Class

AcquiaPurgeService
The Acquia Purge service.

Code

public function deduplicate($path, $list = 'queued', $l = 500) {
  $memcached_backed_storage = $this
    ->hostingInfo()
    ->isMemcachedUsed();

  // And then each $list gets its own subsection.
  if (!isset($this->deduplicateLists[$list])) {
    $this->deduplicateLists[$list] = array();
    if ($memcached_backed_storage) {
      $this->deduplicateLists[$list] = $this
        ->state()
        ->get($list, array())
        ->get();
    }
  }

  // Check if it exists before list rotation, then add missing items.
  $exists = in_array($path, $this->deduplicateLists[$list]);
  if (count($this->deduplicateLists[$list]) >= $l) {
    $this->deduplicateLists[$list] = array();
  }
  if (!$exists) {
    $this->deduplicateLists[$list][] = $path;
    if ($memcached_backed_storage) {
      $this
        ->state()
        ->get($list, array())
        ->set($this->deduplicateLists[$list]);
    }
  }
  return $exists;
}