Increase max number of blocked users loaded from 100 to 1,000 (#4721)

Also includes a little refactor of how the requests are made & how the blocked users are stored
This commit is contained in:
nerix
2023-07-23 13:26:12 +02:00
committed by GitHub
parent a440f0261a
commit fca57696bb
12 changed files with 267 additions and 85 deletions
+82
View File
@@ -0,0 +1,82 @@
#pragma once
#include <atomic>
#include <memory>
namespace chatterino {
/// The CancellationToken is a thread-safe way for worker(s)
/// to know if the task they want to continue doing should be cancelled.
class CancellationToken
{
public:
CancellationToken() = default;
explicit CancellationToken(bool isCancelled)
: isCancelled_(new std::atomic<bool>(isCancelled))
{
}
CancellationToken(const CancellationToken &) = default;
CancellationToken(CancellationToken &&other)
: isCancelled_(std::move(other.isCancelled_)){};
CancellationToken &operator=(CancellationToken &&other)
{
this->isCancelled_ = std::move(other.isCancelled_);
return *this;
}
CancellationToken &operator=(const CancellationToken &) = default;
void cancel()
{
if (this->isCancelled_ != nullptr)
{
this->isCancelled_->store(true, std::memory_order_release);
}
}
bool isCancelled() const
{
return this->isCancelled_ == nullptr ||
this->isCancelled_->load(std::memory_order_acquire);
}
private:
std::shared_ptr<std::atomic<bool>> isCancelled_;
};
/// The ScopedCancellationToken is a way to automatically cancel a CancellationToken when it goes out of scope
class ScopedCancellationToken
{
public:
ScopedCancellationToken() = default;
ScopedCancellationToken(CancellationToken &&backingToken)
: backingToken_(std::move(backingToken))
{
}
ScopedCancellationToken(CancellationToken backingToken)
: backingToken_(std::move(backingToken))
{
}
~ScopedCancellationToken()
{
this->backingToken_.cancel();
}
ScopedCancellationToken(const ScopedCancellationToken &) = delete;
ScopedCancellationToken(ScopedCancellationToken &&other)
: backingToken_(std::move(other.backingToken_)){};
ScopedCancellationToken &operator=(ScopedCancellationToken &&other)
{
this->backingToken_ = std::move(other.backingToken_);
return *this;
}
ScopedCancellationToken &operator=(const ScopedCancellationToken &) =
delete;
private:
CancellationToken backingToken_;
};
} // namespace chatterino