mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 08:18:15 +03:00
49385c8a07
Summary: C++17 Reviewed By: fanzeyi Differential Revision: D28966939 fbshipit-source-id: c8c9d49bc02557263a6acf9357c90b50e04fbdb9
41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This software may be used and distributed according to the terms of the
|
|
* GNU General Public License version 2.
|
|
*/
|
|
|
|
#include "eden/fs/store/BlobAccess.h"
|
|
#include <folly/MapUtil.h>
|
|
#include "eden/fs/model/Blob.h"
|
|
#include "eden/fs/store/BlobCache.h"
|
|
#include "eden/fs/store/IObjectStore.h"
|
|
|
|
namespace facebook::eden {
|
|
|
|
BlobAccess::BlobAccess(
|
|
std::shared_ptr<IObjectStore> objectStore,
|
|
std::shared_ptr<BlobCache> blobCache)
|
|
: objectStore_{std::move(objectStore)}, blobCache_{std::move(blobCache)} {}
|
|
|
|
BlobAccess::~BlobAccess() {}
|
|
|
|
folly::Future<BlobCache::GetResult> BlobAccess::getBlob(
|
|
const Hash& hash,
|
|
ObjectFetchContext& context,
|
|
BlobCache::Interest interest) {
|
|
auto result = blobCache_->get(hash, interest);
|
|
if (result.object) {
|
|
return folly::Future<BlobCache::GetResult>{std::move(result)};
|
|
}
|
|
|
|
return objectStore_->getBlob(hash, context)
|
|
.thenValue([blobCache = blobCache_,
|
|
interest](std::shared_ptr<const Blob> blob) {
|
|
auto interestHandle = blobCache->insert(blob, interest);
|
|
return BlobCache::GetResult{std::move(blob), std::move(interestHandle)};
|
|
});
|
|
}
|
|
|
|
} // namespace facebook::eden
|