Move get_persistent_file_id/get_unique_file_id to FileNode to speed up.
This commit is contained in:
parent
899197448e
commit
2cf1722b5b
@ -765,53 +765,49 @@ bool FileView::can_delete() const {
|
|||||||
return node_->local_.type() == LocalFileLocation::Type::Partial;
|
return node_->local_.type() == LocalFileLocation::Type::Partial;
|
||||||
}
|
}
|
||||||
|
|
||||||
string FileView::get_unique_id(const FullGenerateFileLocation &location) {
|
string FileNode::get_unique_id(const FullGenerateFileLocation &location) {
|
||||||
return base64url_encode(zero_encode('\xff' + serialize(location)));
|
return base64url_encode(zero_encode('\xff' + serialize(location)));
|
||||||
}
|
}
|
||||||
|
|
||||||
string FileView::get_unique_id(const FullRemoteFileLocation &location) {
|
string FileNode::get_unique_id(const FullRemoteFileLocation &location) {
|
||||||
return base64url_encode(zero_encode(serialize(location.as_unique())));
|
return base64url_encode(zero_encode(serialize(location.as_unique())));
|
||||||
}
|
}
|
||||||
|
|
||||||
string FileView::get_persistent_id(const FullGenerateFileLocation &location) {
|
string FileNode::get_persistent_id(const FullGenerateFileLocation &location) {
|
||||||
auto binary = serialize(location);
|
auto binary = serialize(location);
|
||||||
|
|
||||||
binary = zero_encode(binary);
|
binary = zero_encode(binary);
|
||||||
binary.push_back(FileNode::PERSISTENT_ID_VERSION_GENERATED);
|
binary.push_back(PERSISTENT_ID_VERSION_GENERATED);
|
||||||
return base64url_encode(binary);
|
return base64url_encode(binary);
|
||||||
}
|
}
|
||||||
|
|
||||||
string FileView::get_persistent_id(const FullRemoteFileLocation &location) {
|
string FileNode::get_persistent_id(const FullRemoteFileLocation &location) {
|
||||||
auto binary = serialize(location);
|
auto binary = serialize(location);
|
||||||
|
|
||||||
binary = zero_encode(binary);
|
binary = zero_encode(binary);
|
||||||
binary.push_back(static_cast<char>(narrow_cast<uint8>(Version::Next) - 1));
|
binary.push_back(static_cast<char>(narrow_cast<uint8>(Version::Next) - 1));
|
||||||
binary.push_back(FileNode::PERSISTENT_ID_VERSION);
|
binary.push_back(PERSISTENT_ID_VERSION);
|
||||||
return base64url_encode(binary);
|
return base64url_encode(binary);
|
||||||
}
|
}
|
||||||
|
|
||||||
string FileView::get_persistent_file_id() const {
|
string FileNode::get_persistent_file_id() const {
|
||||||
if (!empty()) {
|
if (remote_.is_full_alive) {
|
||||||
if (has_alive_remote_location()) {
|
return get_persistent_id(remote_.full.value());
|
||||||
return get_persistent_id(remote_location());
|
} else if (!url_.empty()) {
|
||||||
} else if (has_url()) {
|
return url_;
|
||||||
return url();
|
} else if (generate_ != nullptr && FileManager::is_remotely_generated_file(generate_->conversion_)) {
|
||||||
} else if (has_generate_location() && FileManager::is_remotely_generated_file(generate_location().conversion_)) {
|
return get_persistent_id(*generate_);
|
||||||
return get_persistent_id(generate_location());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return string();
|
return string();
|
||||||
}
|
}
|
||||||
|
|
||||||
string FileView::get_unique_file_id() const {
|
string FileNode::get_unique_file_id() const {
|
||||||
if (!empty()) {
|
if (remote_.is_full_alive) {
|
||||||
if (has_alive_remote_location()) {
|
if (!remote_.full.value().is_web()) {
|
||||||
if (!remote_location().is_web()) {
|
return get_unique_id(remote_.full.value());
|
||||||
return get_unique_id(remote_location());
|
|
||||||
}
|
|
||||||
} else if (has_generate_location() && FileManager::is_remotely_generated_file(generate_location().conversion_)) {
|
|
||||||
return get_unique_id(generate_location());
|
|
||||||
}
|
}
|
||||||
|
} else if (generate_ != nullptr && FileManager::is_remotely_generated_file(generate_->conversion_)) {
|
||||||
|
return get_unique_id(*generate_);
|
||||||
}
|
}
|
||||||
return string();
|
return string();
|
||||||
}
|
}
|
||||||
@ -3173,16 +3169,18 @@ FileView FileManager::get_sync_file_view(FileId file_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
td_api::object_ptr<td_api::file> FileManager::get_file_object(FileId file_id, bool with_main_file_id) {
|
td_api::object_ptr<td_api::file> FileManager::get_file_object(FileId file_id, bool with_main_file_id) {
|
||||||
auto file_view = get_sync_file_view(file_id);
|
auto file_node_ptr = get_sync_file_node(file_id);
|
||||||
|
if (!file_node_ptr) {
|
||||||
if (file_view.empty()) {
|
|
||||||
return td_api::make_object<td_api::file>(0, 0, 0, td_api::make_object<td_api::localFile>(),
|
return td_api::make_object<td_api::file>(0, 0, 0, td_api::make_object<td_api::localFile>(),
|
||||||
td_api::make_object<td_api::remoteFile>());
|
td_api::make_object<td_api::remoteFile>());
|
||||||
}
|
}
|
||||||
|
|
||||||
string persistent_file_id = file_view.get_persistent_file_id();
|
const FileNode *file_node = file_node_ptr.get();
|
||||||
string unique_file_id = file_view.get_unique_file_id();
|
string persistent_file_id = file_node->get_persistent_file_id();
|
||||||
|
string unique_file_id = file_node->get_unique_file_id();
|
||||||
bool is_uploading_completed = !persistent_file_id.empty();
|
bool is_uploading_completed = !persistent_file_id.empty();
|
||||||
|
|
||||||
|
auto file_view = FileView(file_node_ptr);
|
||||||
auto size = file_view.size();
|
auto size = file_view.size();
|
||||||
auto expected_size = file_view.expected_size();
|
auto expected_size = file_view.expected_size();
|
||||||
auto download_offset = file_view.download_offset();
|
auto download_offset = file_view.download_offset();
|
||||||
|
@ -194,7 +194,18 @@ class FileNode {
|
|||||||
void init_ready_size();
|
void init_ready_size();
|
||||||
|
|
||||||
void recalc_ready_prefix_size(int64 prefix_offset, int64 ready_prefix_size);
|
void recalc_ready_prefix_size(int64 prefix_offset, int64 ready_prefix_size);
|
||||||
|
|
||||||
void update_effective_download_limit(int64 old_download_limit);
|
void update_effective_download_limit(int64 old_download_limit);
|
||||||
|
|
||||||
|
string get_persistent_file_id() const;
|
||||||
|
|
||||||
|
string get_unique_file_id() const;
|
||||||
|
|
||||||
|
static string get_unique_id(const FullGenerateFileLocation &location);
|
||||||
|
static string get_unique_id(const FullRemoteFileLocation &location);
|
||||||
|
|
||||||
|
static string get_persistent_id(const FullGenerateFileLocation &location);
|
||||||
|
static string get_persistent_id(const FullRemoteFileLocation &location);
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileManager;
|
class FileManager;
|
||||||
@ -334,18 +345,15 @@ class FileView {
|
|||||||
type != PhotoSizeSource::Type::Thumbnail;
|
type != PhotoSizeSource::Type::Thumbnail;
|
||||||
}
|
}
|
||||||
|
|
||||||
string get_persistent_file_id() const;
|
string get_unique_file_id() const {
|
||||||
|
if (!empty()) {
|
||||||
string get_unique_file_id() const;
|
return node_->get_unique_file_id();
|
||||||
|
}
|
||||||
|
return string();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ConstFileNodePtr node_{};
|
ConstFileNodePtr node_{};
|
||||||
|
|
||||||
static string get_unique_id(const FullGenerateFileLocation &location);
|
|
||||||
static string get_unique_id(const FullRemoteFileLocation &location);
|
|
||||||
|
|
||||||
static string get_persistent_id(const FullGenerateFileLocation &location);
|
|
||||||
static string get_persistent_id(const FullRemoteFileLocation &location);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileManager final : public FileLoadManager::Callback {
|
class FileManager final : public FileLoadManager::Callback {
|
||||||
|
Loading…
Reference in New Issue
Block a user