Skip to content

Commit

Permalink
Merge pull request #1646 from Expensify/main
Browse files Browse the repository at this point in the history
Update expensify_prod branch
  • Loading branch information
bondydaa authored Feb 19, 2024
2 parents f4e6af1 + 84db353 commit e970726
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
22 changes: 17 additions & 5 deletions BedrockCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ BedrockCommand::BedrockCommand(SQLiteCommand&& baseCommand, BedrockPlugin* plugi
_plugin(plugin),
_commitEmptyTransactions(false),
_inProgressTiming(INVALID, 0, 0),
_timeout(_getTimeout(request, scheduledTime))
_timeout(_getTimeout(request, scheduledTime)),
_lastContiguousCompletedTransaction(httpsRequests.end())
{
// Initialize the priority, if supplied.
if (request.isSet("priority")) {
Expand Down Expand Up @@ -110,10 +111,14 @@ void BedrockCommand::stopTiming(TIMING_INFO type) {
}

bool BedrockCommand::areHttpsRequestsComplete() const {
for (auto request : httpsRequests) {
if (!request->response) {
auto requestIt = (_lastContiguousCompletedTransaction == httpsRequests.end()) ? httpsRequests.begin() : _lastContiguousCompletedTransaction;
while (requestIt != httpsRequests.end()) {
if (!(*requestIt)->response) {
return false;
} else {
_lastContiguousCompletedTransaction = requestIt;
}
requestIt++;
}
return true;
}
Expand Down Expand Up @@ -277,14 +282,20 @@ void BedrockCommand::finalizeTimingInfo() {

void BedrockCommand::prePoll(fd_map& fdm)
{
for (auto& transaction : httpsRequests) {
auto requestIt = (_lastContiguousCompletedTransaction == httpsRequests.end()) ? httpsRequests.begin() : _lastContiguousCompletedTransaction;
while (requestIt != httpsRequests.end()) {
SHTTPSManager::Transaction* transaction = *requestIt;
transaction->manager.prePoll(fdm, *transaction);
requestIt++;
}
}

void BedrockCommand::postPoll(fd_map& fdm, uint64_t nextActivity, uint64_t maxWaitMS)
{
for (auto& transaction : httpsRequests) {
auto requestIt = (_lastContiguousCompletedTransaction == httpsRequests.end()) ? httpsRequests.begin() : _lastContiguousCompletedTransaction;
while (requestIt != httpsRequests.end()) {
SHTTPSManager::Transaction* transaction = *requestIt;

// If nothing else has set the timeout for this request (i.e., a HTTPS manager that expects to receive a
// response in a particular time), we will set the timeout here to match the timeout of the command so that we
// can't go "too long" waiting for a response.
Expand All @@ -293,6 +304,7 @@ void BedrockCommand::postPoll(fd_map& fdm, uint64_t nextActivity, uint64_t maxWa
transaction->timeoutAt = _timeout;
}
transaction->manager.postPoll(fdm, *transaction, nextActivity, maxWaitMS);
requestIt++;
}
}

Expand Down
12 changes: 12 additions & 0 deletions BedrockCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,16 @@ class BedrockCommand : public SQLiteCommand {
static SStandaloneHTTPSManager _noopHTTPSManager;

static const string defaultPluginName;

// This refers to the last request in httpsRequests for which all previous requests (including the one referred to) are known to be complete.
// For instance, if there are 10 requests (0-9) in httpsRequests, and 0, 1, 2, 5, and 8 are complete, this can refer to request 2, the last one completed
// for which all previous requests are also completed.
// This is only updated when `areHttpsRequestsComplete()` is called, hence "known to be complete". Requests may have completed that are not yet known, but no
// requests can exist before this iterator that are incomplete.
// This is used as an optimization. For some operations (areHttpsRequestsComplete, prePoll, postPoll) we iterate across httpsReqeusts, but only actually need to iterate
// across httpsRequests that have not yet finished. This allows us to skip known finished requests. If a command has 1,000 attached requests, and on the previous loop
// it was known that 990 of them had completed, then on the next loop we can use this to check only the remaining 10 requests rather than all 1,000.
//
// The default value of this is httpsRequests.end(), which is treated as "no requests completed".
mutable list<SHTTPSManager::Transaction*>::const_iterator _lastContiguousCompletedTransaction;
};

0 comments on commit e970726

Please sign in to comment.