如何解决Google Cloud Storage - 计算非常大的存储桶中的对象
我正在尝试加快计算存储桶中对象(文件)数量的方法。我当前的方法对于大存储桶(通常包含 50k 或更多对象)变得非常慢。我想获取存储桶中对象的总数,以及超过某个阈值的对象数。
$storage_client = GoogleCloudStorageNew::client();
$bucket = $storage_client->bucket( $myBucketName );
$this->threshold_hours = 3;
$threshold = time() - ( 60 * 60 * $this->threshold_hours );
$threshold_timestamp = date('Y-m-d H:i:s',$threshold);
$params = [
'prefix' => "$mls_id/",'pagetoken' => null
];
$this->total_images = 0;
$this->total_old_images = 0;
foreach ( $bucket->objects( $params ) as $object )
{
// always add to total
$this->total_images++;
$info = $object->info();
$image_created = date( 'Y-m-d H:i:s',strtotime( $info['timeCreated']) );
if ( $image_created < $threshold_timestamp )
{
$this->total_old_images++;
}
}
我想知道尝试分页结果是否会更快,但我无法使分页工作。使用相同的设置,我尝试了这个:
$page_token = null;
$params = [
'prefix' => "$mls_id/",'maxResults' => 5000,'pagetoken' => null
];
$this->total_images = 0;
$this->total_old_images = 0;
$this->threshold_hours = 3;
$threshold = time() - ( 60 * 60 * $this->threshold_hours );
$threshold_timestamp = date('Y-m-d H:i:s',$threshold);
while ( $objectList = $bucket->objects($params) )
{
$params['pagetoken'] = $objectList->nextResultToken();
foreach ( $objectList as $object )
{
$this->total_images++;
$info = $object->info();
$image_created = date( 'Y-m-d H:i:s',strtotime( $info['timeCreated']) );
if ( $image_created < $threshold_timestamp )
{
$this->total_old_images++;
}
}
}
但是分页不起作用 - maxResults 不限制返回到 5000 的内容,它只是获取所有内容。我是否误读了 maxResults/pagetoken 和 nextResultToken() 如何协同工作?显然,我是,但我错过了什么?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。