添加缓存
This commit is contained in:
1 parent
4d7dde104d
commit
fb63205a70
4 files changed
+132
-7
No files matched your search
@@ -3,6 +3,7 @@
|
||||
#include "seafile/fs/file_context.hpp"
|
||||
#include "util/string_util.hpp"
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <format>
|
||||
|
||||
namespace seafile::fs {
|
||||
namespace {
|
||||
@@ -26,7 +27,8 @@ namespace seafile::fs {
|
||||
return (static_cast<int64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
|
||||
}
|
||||
|
||||
void SetFileInfo(FSP_FSCTL_FILE_INFO *FileInfo, const uint32_t attributes, const uint64_t size,const int64_t mtime) {
|
||||
void SetFileInfo(FSP_FSCTL_FILE_INFO *FileInfo, const uint32_t attributes, const uint64_t size,
|
||||
const int64_t mtime) {
|
||||
FileInfo->FileAttributes = attributes;
|
||||
FileInfo->AllocationSize = size;
|
||||
FileInfo->FileSize = size;
|
||||
@@ -156,7 +158,7 @@ namespace seafile::fs {
|
||||
const auto copy_len = (std::min)(data.size(), static_cast<size_t>(Length));
|
||||
memcpy(Buffer, data.data(), copy_len);
|
||||
*PBytesTransferred = static_cast<ULONG>(copy_len);
|
||||
spdlog::info(std::format("read file {} bytes offset {} length {} success", fc->path,Offset, Length));
|
||||
spdlog::info(std::format("read file {} bytes offset {} length {} success", fc->path, Offset, Length));
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
@@ -166,11 +168,19 @@ namespace seafile::fs {
|
||||
PVOID Buffer, ULONG BufferLength, PULONG PBytesTransferred) {
|
||||
const auto fc = static_cast<SeaFileContext *>(FileContext);
|
||||
*PBytesTransferred = 0;
|
||||
const auto path = std::ranges::replace(fc->path, '\\', '/');
|
||||
const auto entries_result = api.repoDir(fc->repo_id, fc->path, token, token_type);
|
||||
const auto cache_key = std::format("{}_{}", fc->repo_id, fc->path);
|
||||
auto repo_entries = repo_dir_cache.get(cache_key);
|
||||
if (!repo_entries.has_value()) {
|
||||
if (auto entries_result = api.repoDir(fc->repo_id, fc->path, token, token_type); entries_result.has_value()) {
|
||||
repo_entries = entries_result.value();
|
||||
repo_dir_cache.put(cache_key, repo_entries.value(),std::chrono::seconds(60));
|
||||
}else {
|
||||
spdlog::error(std::format("can't read directory {},due to {}", fc->path,entries_result.error().what()));
|
||||
}
|
||||
}
|
||||
|
||||
if (entries_result.has_value()) {
|
||||
const auto &entries = entries_result.value();
|
||||
if (repo_entries.has_value()) {
|
||||
const auto &entries = repo_entries.value();
|
||||
size_t start = 0;
|
||||
if (Marker) {
|
||||
const auto marker = shell::util::StringUtil::utf16le_to_utf8(Marker);
|
||||
@@ -208,7 +218,6 @@ namespace seafile::fs {
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
std::cout << entries_result.error().what() << std::endl;
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user