0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-08 04:58:58 +02:00

ircd:Ⓜ️:sync: Add next_batch central convenience; add branding to token.

This commit is contained in:
Jason Volk 2020-01-06 12:51:34 -08:00
parent 559a0dd7ac
commit d9c7985376
4 changed files with 38 additions and 15 deletions

View file

@ -27,6 +27,9 @@ namespace ircd::m::sync
string_view loghead(const data &);
string_view make_since(const mutable_buffer &, const int64_t &);
string_view make_since(const mutable_buffer &, const m::events::range &);
bool apropos(const data &, const event::idx &);
bool apropos(const data &, const event::id &);
bool apropos(const data &, const event &);

View file

@ -125,6 +125,29 @@ ircd::m::sync::apropos(const data &d,
(event_idx >= d.range.first && event_idx < d.range.second);
}
ircd::string_view
ircd::m::sync::make_since(const mutable_buffer &buf,
const int64_t &val)
{
return fmt::sprintf
{
buf, "ctor_%lu",
val
};
}
ircd::string_view
ircd::m::sync::make_since(const mutable_buffer &buf,
const m::events::range &val)
{
return fmt::sprintf
{
buf, "ctor_%lu_%lu",
val.first,
val.second,
};
}
ircd::string_view
ircd::m::sync::loghead(const data &data)
{

View file

@ -57,7 +57,7 @@ get__members(client &client,
// parse this token for the snapshot integer.
const auto &[since, snapshot]
{
split(at, '_')
split(lstrip(at, "ctor_"), '_')
};
const auto at_idx

View file

@ -387,11 +387,12 @@ ircd::m::sync::empty_response(data &data,
top, "presence"
};
char buf[64];
json::stack::member
{
top, "next_batch", json::value
{
lex_cast(next_batch), json::STRING
make_since(buf, next_batch), json::STRING
}
};
@ -492,23 +493,17 @@ try
// second part is the next_batch upper-bound integer which is a snapshot
// of the server's sequence number when the phased sync started.
data.phased?
fmt::sprintf
{
buf, "%ld_%lu", next_batch, data.range.second
}:
make_since(buf, m::events::range{next_batch, data.range.second}):
// The normal integer since token.
fmt::sprintf
{
buf, "%ld", next_batch
}
make_since(buf, next_batch)
};
json::stack::member
{
*data.out, "next_batch", json::value
{
next_batch_token ,json::STRING
next_batch_token, json::STRING
}
};
}
@ -603,11 +598,12 @@ try
if(last)
{
char buf[64];
json::stack::member
{
top, "next_batch", json::value
{
lex_cast(next), json::STRING
make_since(buf, next), json::STRING
}
};
@ -966,11 +962,12 @@ ircd::m::sync::longpoll::polled(data &data,
std::min(data.range.second + 1, vm::sequence::retired + 1)
};
char since_buf[64];
json::stack::member
{
top, "next_batch", json::value
{
lex_cast(next), json::STRING
make_since(since_buf, next), json::STRING
}
};
@ -1092,7 +1089,7 @@ try
}
,since_token
{
split(request.query.get("since", "0"_sv), '_')
split(lstrip(request.query.get("since", "0"_sv), "ctor_"), '_')
}
,since
{
@ -1104,7 +1101,7 @@ try
}
,next_batch
{
uint64_t(lex_cast<int64_t>(next_batch_token?: "-1"_sv))
uint64_t(lex_cast<uint64_t>(next_batch_token?: "-1"_sv))
}
,timesout
{