mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 23:38:50 +03:00
0d634a1296
Summary: In support of making Eden's file access stateless, add a facade that connects the BlobCache and ObjectStore, allowing FileInode to fetch blobs, minimizing reloads and memory usage. Reviewed By: strager Differential Revision: D10850143 fbshipit-source-id: 4307f7c1143aecad1284ea3cadf3e4efca9a3925
43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2018-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
*/
|
|
#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 {
|
|
namespace 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,
|
|
BlobCache::Interest interest) {
|
|
auto result = blobCache_->get(hash, interest);
|
|
if (result.blob) {
|
|
return std::move(result);
|
|
}
|
|
|
|
return objectStore_->getBlob(hash).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 eden
|
|
} // namespace facebook
|