Use WaitFreeHashMap for document storages.

This commit is contained in:
levlam 2022-08-04 10:50:34 +03:00
parent 08dbc7d9f2
commit 29460cacc8
12 changed files with 19 additions and 60 deletions

View File

@ -229,13 +229,7 @@ FileId AnimationsManager::on_get_animation(unique_ptr<Animation> new_animation,
}
const AnimationsManager::Animation *AnimationsManager::get_animation(FileId file_id) const {
auto animation = animations_.find(file_id);
if (animation == animations_.end()) {
return nullptr;
}
CHECK(animation->second->file_id == file_id);
return animation->second.get();
return animations_.get_pointer(file_id);
}
FileId AnimationsManager::get_animation_thumbnail_file_id(FileId file_id) const {

View File

@ -18,9 +18,9 @@
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include "td/utils/WaitFreeHashMap.h"
namespace td {
@ -145,7 +145,7 @@ class AnimationsManager final : public Actor {
Td *td_;
ActorShared<> parent_;
FlatHashMap<FileId, unique_ptr<Animation>, FileIdHash> animations_;
WaitFreeHashMap<FileId, unique_ptr<Animation>, FileIdHash> animations_;
int32 saved_animations_limit_ = 200;
vector<FileId> saved_animation_ids_;

View File

@ -122,13 +122,7 @@ FileId AudiosManager::on_get_audio(unique_ptr<Audio> new_audio, bool replace) {
}
const AudiosManager::Audio *AudiosManager::get_audio(FileId file_id) const {
auto audio = audios_.find(file_id);
if (audio == audios_.end()) {
return nullptr;
}
CHECK(audio->second->file_id == file_id);
return audio->second.get();
return audios_.get_pointer(file_id);
}
FileId AudiosManager::dup_audio(FileId new_id, FileId old_id) {

View File

@ -14,7 +14,7 @@
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/WaitFreeHashMap.h"
namespace td {
@ -82,7 +82,7 @@ class AudiosManager {
FileId on_get_audio(unique_ptr<Audio> new_audio, bool replace);
Td *td_;
FlatHashMap<FileId, unique_ptr<Audio>, FileIdHash> audios_;
WaitFreeHashMap<FileId, unique_ptr<Audio>, FileIdHash> audios_;
};
} // namespace td

View File

@ -579,13 +579,7 @@ void DocumentsManager::create_document(FileId file_id, string minithumbnail, Pho
}
const DocumentsManager::GeneralDocument *DocumentsManager::get_document(FileId file_id) const {
auto document = documents_.find(file_id);
if (document == documents_.end()) {
return nullptr;
}
CHECK(document->second->file_id == file_id);
return document->second.get();
return documents_.get_pointer(file_id);
}
bool DocumentsManager::has_input_media(FileId file_id, FileId thumbnail_file_id, bool is_secret) const {

View File

@ -19,7 +19,7 @@
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/WaitFreeHashMap.h"
#include <utility>
@ -131,7 +131,7 @@ class DocumentsManager {
FileId on_get_document(unique_ptr<GeneralDocument> new_document, bool replace);
Td *td_;
FlatHashMap<FileId, unique_ptr<GeneralDocument>, FileIdHash> documents_; // file_id -> GeneralDocument
WaitFreeHashMap<FileId, unique_ptr<GeneralDocument>, FileIdHash> documents_; // file_id -> GeneralDocument
};
} // namespace td

View File

@ -75,13 +75,7 @@ FileId VideoNotesManager::on_get_video_note(unique_ptr<VideoNote> new_video_note
}
const VideoNotesManager::VideoNote *VideoNotesManager::get_video_note(FileId file_id) const {
auto video_note = video_notes_.find(file_id);
if (video_note == video_notes_.end()) {
return nullptr;
}
CHECK(video_note->second->file_id == file_id);
return video_note->second.get();
return video_notes_.get_pointer(file_id);
}
FileId VideoNotesManager::get_video_note_thumbnail_file_id(FileId file_id) const {

View File

@ -15,7 +15,7 @@
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/WaitFreeHashMap.h"
namespace td {
@ -75,7 +75,7 @@ class VideoNotesManager {
FileId on_get_video_note(unique_ptr<VideoNote> new_video_note, bool replace);
Td *td_;
FlatHashMap<FileId, unique_ptr<VideoNote>, FileIdHash> video_notes_;
WaitFreeHashMap<FileId, unique_ptr<VideoNote>, FileIdHash> video_notes_;
};
} // namespace td

View File

@ -105,13 +105,7 @@ FileId VideosManager::on_get_video(unique_ptr<Video> new_video, bool replace) {
}
const VideosManager::Video *VideosManager::get_video(FileId file_id) const {
auto video = videos_.find(file_id);
if (video == videos_.end()) {
return nullptr;
}
CHECK(video->second->file_id == file_id);
return video->second.get();
return videos_.get_pointer(file_id);
}
FileId VideosManager::get_video_thumbnail_file_id(FileId file_id) const {

View File

@ -15,7 +15,7 @@
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/WaitFreeHashMap.h"
namespace td {
@ -89,7 +89,7 @@ class VideosManager {
FileId on_get_video(unique_ptr<Video> new_video, bool replace);
Td *td_;
FlatHashMap<FileId, unique_ptr<Video>, FileIdHash> videos_;
WaitFreeHashMap<FileId, unique_ptr<Video>, FileIdHash> videos_;
};
} // namespace td

View File

@ -190,23 +190,11 @@ FileId VoiceNotesManager::on_get_voice_note(unique_ptr<VoiceNote> new_voice_note
}
VoiceNotesManager::VoiceNote *VoiceNotesManager::get_voice_note(FileId file_id) {
auto voice_note = voice_notes_.find(file_id);
if (voice_note == voice_notes_.end()) {
return nullptr;
}
CHECK(voice_note->second->file_id == file_id);
return voice_note->second.get();
return voice_notes_.get_pointer(file_id);
}
const VoiceNotesManager::VoiceNote *VoiceNotesManager::get_voice_note(FileId file_id) const {
auto voice_note = voice_notes_.find(file_id);
if (voice_note == voice_notes_.end()) {
return nullptr;
}
CHECK(voice_note->second->file_id == file_id);
return voice_note->second.get();
return voice_notes_.get_pointer(file_id);
}
FileId VoiceNotesManager::dup_voice_note(FileId new_id, FileId old_id) {

View File

@ -20,6 +20,7 @@
#include "td/utils/FlatHashSet.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include "td/utils/WaitFreeHashMap.h"
namespace td {
@ -104,7 +105,7 @@ class VoiceNotesManager final : public Actor {
Td *td_;
ActorShared<> parent_;
FlatHashMap<FileId, unique_ptr<VoiceNote>, FileIdHash> voice_notes_;
WaitFreeHashMap<FileId, unique_ptr<VoiceNote>, FileIdHash> voice_notes_;
FlatHashMap<FileId, vector<Promise<Unit>>, FileIdHash> speech_recognition_queries_;
FlatHashMap<int64, FileId> pending_voice_note_transcription_queries_;