public function loadPage()
 {
     $table = new DifferentialChangeset();
     $conn_r = $table->establishConnection('r');
     $data = queryfx_all($conn_r, 'SELECT * FROM %T %Q %Q %Q', $table->getTableName(), $this->buildWhereClause($conn_r), $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r));
     return $table->loadAllFromArray($data);
 }
 protected function collectGarbage()
 {
     $table = new DifferentialChangeset();
     $conn_w = $table->establishConnection('w');
     queryfx($conn_w, 'DELETE FROM %T WHERE dateCreated < %d LIMIT 100', DifferentialChangeset::TABLE_CACHE, $this->getGarbageEpoch());
     return $conn_w->getAffectedRows() == 100;
 }
 public function collectGarbage()
 {
     $key = 'gcdaemon.ttl.differential-parse-cache';
     $ttl = PhabricatorEnv::getEnvConfig($key);
     if ($ttl <= 0) {
         return false;
     }
     $table = new DifferentialChangeset();
     $conn_w = $table->establishConnection('w');
     queryfx($conn_w, 'DELETE FROM %T WHERE dateCreated < %d LIMIT 100', DifferentialChangeset::TABLE_CACHE, time() - $ttl);
     return $conn_w->getAffectedRows() == 100;
 }
 public function saveCache()
 {
     $render_cache_key = $this->getRenderCacheKey();
     if (!$render_cache_key) {
         return false;
     }
     $cache = array();
     foreach (self::getCacheableProperties() as $cache_key) {
         switch ($cache_key) {
             case 'cacheVersion':
                 $cache[$cache_key] = self::CACHE_VERSION;
                 break;
             case 'cacheHost':
                 $cache[$cache_key] = php_uname('n');
                 break;
             default:
                 $cache[$cache_key] = $this->{$cache_key};
                 break;
         }
     }
     $cache = json_encode($cache);
     try {
         $changeset = new DifferentialChangeset();
         $conn_w = $changeset->establishConnection('w');
         queryfx($conn_w, 'INSERT INTO %T (id, cache, dateCreated) VALUES (%d, %s, %d)
       ON DUPLICATE KEY UPDATE cache = VALUES(cache)', DifferentialChangeset::TABLE_CACHE, $render_cache_key, $cache, time());
     } catch (AphrontQueryException $ex) {
         // TODO: uhoh
     }
 }
 public function saveCache()
 {
     if ($this->highlightErrors) {
         return false;
     }
     $render_cache_key = $this->getRenderCacheKey();
     if (!$render_cache_key) {
         return false;
     }
     $cache = array();
     foreach (self::getCacheableProperties() as $cache_key) {
         switch ($cache_key) {
             case 'cacheVersion':
                 $cache[$cache_key] = self::CACHE_VERSION;
                 break;
             case 'cacheHost':
                 $cache[$cache_key] = php_uname('n');
                 break;
             default:
                 $cache[$cache_key] = $this->{$cache_key};
                 break;
         }
     }
     $cache = json_encode($cache);
     // We don't want to waste too much space by a single changeset.
     if (strlen($cache) > self::CACHE_MAX_SIZE) {
         return;
     }
     try {
         $changeset = new DifferentialChangeset();
         $conn_w = $changeset->establishConnection('w');
         $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
         queryfx($conn_w, 'INSERT INTO %T (id, cache, dateCreated) VALUES (%d, %s, %d)
       ON DUPLICATE KEY UPDATE cache = VALUES(cache)', DifferentialChangeset::TABLE_CACHE, $render_cache_key, $cache, time());
     } catch (AphrontQueryException $ex) {
         // TODO: uhoh
     }
 }
 public function saveCache()
 {
     if (PhabricatorEnv::isReadOnly()) {
         return false;
     }
     if ($this->highlightErrors) {
         return false;
     }
     $render_cache_key = $this->getRenderCacheKey();
     if (!$render_cache_key) {
         return false;
     }
     $cache = array();
     foreach (self::getCacheableProperties() as $cache_key) {
         switch ($cache_key) {
             case 'cacheVersion':
                 $cache[$cache_key] = self::CACHE_VERSION;
                 break;
             case 'cacheHost':
                 $cache[$cache_key] = php_uname('n');
                 break;
             default:
                 $cache[$cache_key] = $this->{$cache_key};
                 break;
         }
     }
     $cache = serialize($cache);
     // We don't want to waste too much space by a single changeset.
     if (strlen($cache) > self::CACHE_MAX_SIZE) {
         return;
     }
     $changeset = new DifferentialChangeset();
     $conn_w = $changeset->establishConnection('w');
     $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
     try {
         queryfx($conn_w, 'INSERT INTO %T (id, cache, dateCreated) VALUES (%d, %B, %d)
         ON DUPLICATE KEY UPDATE cache = VALUES(cache)', DifferentialChangeset::TABLE_CACHE, $render_cache_key, $cache, time());
     } catch (AphrontQueryException $ex) {
         // Ignore these exceptions. A common cause is that the cache is
         // larger than 'max_allowed_packet', in which case we're better off
         // not writing it.
         // TODO: It would be nice to tailor this more narrowly.
     }
     unset($unguarded);
 }
Exemple #7
0
            $purge_differential = true;
            break;
        case '--maniphest':
            $purge_maniphest = true;
            break;
        case '--help':
            return help();
        default:
            return usage("Unrecognized argument '{$args[$ii]}'.");
    }
}
if ($purge_changesets) {
    $table = new DifferentialChangeset();
    if ($changesets) {
        echo "Purging changeset cache for changesets " . implode($changesets, ",") . "\n";
        queryfx($table->establishConnection('w'), 'DELETE FROM %T WHERE id IN (%Ld)', DifferentialChangeset::TABLE_CACHE, $changesets);
    } else {
        echo "Purging changeset cache...\n";
        queryfx($table->establishConnection('w'), 'TRUNCATE TABLE %T', DifferentialChangeset::TABLE_CACHE);
    }
    echo "Done.\n";
}
if ($purge_differential) {
    echo "Purging Differential comment cache...\n";
    $table = new DifferentialComment();
    queryfx($table->establishConnection('w'), 'UPDATE %T SET cache = NULL', $table->getTableName());
    echo "Purging Differential inline comment cache...\n";
    $table = new DifferentialInlineComment();
    queryfx($table->establishConnection('w'), 'UPDATE %T SET cache = NULL', $table->getTableName());
    echo "Done.\n";
}
        case '--differential':
            $purge_differential = true;
            break;
        case '--maniphest':
            $purge_maniphest = true;
            break;
        case '--help':
            return help();
        default:
            return usage("Unrecognized argument '{$arg}'.");
    }
}
if ($purge_changesets) {
    echo "Purging changeset cache...\n";
    $table = new DifferentialChangeset();
    queryfx($table->establishConnection('w'), 'TRUNCATE TABLE %T', DifferentialChangeset::TABLE_CACHE);
    echo "Done.\n";
}
if ($purge_differential) {
    echo "Purging Differential comment cache...\n";
    $table = new DifferentialComment();
    queryfx($table->establishConnection('w'), 'UPDATE %T SET cache = NULL', $table->getTableName());
    echo "Done.\n";
}
if ($purge_maniphest) {
    echo "Purging Maniphest comment cache...\n";
    $table = new ManiphestTransaction();
    queryfx($table->establishConnection('w'), 'UPDATE %T SET cache = NULL', $table->getTableName());
    echo "Done.\n";
}
echo "Ok, caches purged.\n";