4

我从数据存储中删除了大量不需要的对象(大约 7000 个)。这些对象中的每一个都有一个与之关联的 blob,由字符串(blob 键)引用。

正如您现在可能已经猜到的那样,我忘记删除这些 blob。现在我对它们没有任何参考,但我想删除它们。我似乎找不到办法做到这一点。任何帮助将不胜感激。

更新 找到了解决方案。

DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
List<BlobInfo> blobsToCheck = new LinkedList<BlobInfo>(); 
Iterator<BlobInfo> iterator = null;
if(afterBlobKey == null){
    iterator = new BlobInfoFactory().queryBlobInfos();
}else{
    iterator = new BlobInfoFactory().queryBlobInfosAfter(new BlobKey(afterBlobKey));
}

while(iterator.hasNext()){

    blobsToCheck.add(iterator.next());

}

//Check those blobs if they have reference in datastore
//Delete using blobstoreService.delete(blobKey);
4

1 回答 1

11

更新找到了解决方案,BlobInfoFactory().queryBlobInfos() 是我正在寻找的。

    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
    List<BlobInfo> blobsToCheck = new LinkedList<BlobInfo>(); 
    Iterator<BlobInfo> iterator = null;
    if(afterBlobKey == null){
        iterator = new BlobInfoFactory().queryBlobInfos();
    }else{
        iterator = new BlobInfoFactory().queryBlobInfosAfter(new BlobKey(afterBlobKey));
    }

    while(iterator.hasNext()){

        blobsToCheck.add(iterator.next());

    }

    //Check those blobs if they have reference in datastore
    //Delete using blobstoreService.delete(blobKey);
于 2011-03-20T09:05:17.163 回答