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

modules/client/sync: Add conf items which override the sync mode selection.

This commit is contained in:
Jason Volk 2019-03-07 11:53:58 -08:00
parent 34561a5659
commit 5adfb3ba43
2 changed files with 46 additions and 7 deletions

View file

@ -56,6 +56,20 @@ ircd::m::sync::linear_delta_max
{ "default", 1024 },
};
decltype(ircd::m::sync::polylog_only)
ircd::m::sync::polylog_only
{
{ "name", "ircd.client.sync.polylog_only" },
{ "default", false },
};
decltype(ircd::m::sync::longpoll_enable)
ircd::m::sync::longpoll_enable
{
{ "name", "ircd.client.sync.longpoll.enable" },
{ "default", true },
};
//
// GET sync
//
@ -129,11 +143,23 @@ ircd::m::sync::handle_get(client &client,
log, "request %s", loghead(data)
};
const bool should_longpoll
{
range.first > range.second
};
const bool should_linear
{
!should_longpoll &&
!bool(polylog_only) &&
range.second - range.first <= size_t(linear_delta_max)
};
const bool shortpolled
{
range.first > range.second?
should_longpoll?
false:
range.second - range.first <= size_t(linear_delta_max)?
should_linear?
linear_handle(data):
polylog_handle(data)
};
@ -142,17 +168,25 @@ ircd::m::sync::handle_get(client &client,
if(shortpolled)
return {};
if(longpoll::poll(data, args))
if(longpoll_enable && longpoll::poll(data, args))
return {};
const auto &next_batch
{
polylog_only?
data.range.first:
data.range.second
};
// A user-timeout occurred. According to the spec we return a
// 200 with empty fields rather than a 408.
empty_response(data);
empty_response(data, next_batch);
return {};
}
void
ircd::m::sync::empty_response(data &data)
ircd::m::sync::empty_response(data &data,
const uint64_t &next_batch)
{
json::stack::object top
{
@ -174,7 +208,7 @@ ircd::m::sync::empty_response(data &data)
{
top, "next_batch", json::value
{
lex_cast(data.range.second), json::STRING
lex_cast(next_batch), json::STRING
}
};
}
@ -533,6 +567,9 @@ try
queue.pop_front();
}};
if(polylog_only)
return false;
if(handle(data, args, accepted))
return true;
}

View file

@ -22,9 +22,11 @@ namespace ircd::m::sync
extern conf::item<size_t> flush_hiwat;
extern conf::item<size_t> buffer_size;
extern conf::item<size_t> linear_delta_max;
extern conf::item<bool> longpoll_enable;
extern conf::item<bool> polylog_only;
static const_buffer flush(data &, resource::response::chunked &, const const_buffer &);
static void empty_response(data &);
static void empty_response(data &, const uint64_t &next_batch);
static bool linear_handle(data &);
static bool polylog_handle(data &);
static resource::response handle_get(client &, const resource::request &);