0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-01-13 16:33:53 +01:00

ircd:Ⓜ️:sync: Make data.out a pointer to the json::stack.

This commit is contained in:
Jason Volk 2019-02-26 15:50:58 -08:00
parent 1ad1c38a53
commit 78a1281b1c
14 changed files with 75 additions and 74 deletions

View file

@ -89,7 +89,7 @@ struct ircd::m::sync::data
const m::filter filter;
/// The json::stack master object
json::stack out;
json::stack *out {nullptr};
// apropos contextual
const m::event *event {nullptr};
@ -99,10 +99,8 @@ struct ircd::m::sync::data
data(const m::user &user,
const m::events::range &range,
const mutable_buffer &,
json::stack::flush_callback,
const size_t &flush_hiwat = 64_KiB,
ircd::client *const &client = nullptr,
json::stack *const &out = nullptr,
sync::stats *const &stats = nullptr,
const string_view &filter_id = {});

View file

@ -536,7 +536,9 @@ ircd::m::sync::loghead(const data &data)
string_view{data.user.user_id},
data.range.first,
data.range.second,
ircd::pretty(iecbuf[0], iec(flush_bytes + size(data.out.completed()))),
data.out?
ircd::pretty(iecbuf[0], iec(flush_bytes + size(data.out->completed()))):
string_view{},
flush_count,
ircd::pretty(iecbuf[1], iec(flush_bytes)),
tmstr
@ -551,10 +553,8 @@ ircd::m::sync::data::data
(
const m::user &user,
const m::events::range &range,
const mutable_buffer &buf,
json::stack::flush_callback flusher,
const size_t &flush_hiwat,
ircd::client *const &client,
json::stack *const &out,
sync::stats *const &stats,
const string_view &filter_id
)
@ -598,7 +598,7 @@ ircd::m::sync::data::data
}
,out
{
buf, std::move(flusher), flush_hiwat
out
}
{
}

View file

@ -98,6 +98,18 @@ ircd::m::sync::handle_get(client &client,
"Since parameter is too far in the future..."
};
// Keep state for statistics of this sync here on the stack.
stats stats;
data data
{
request.user_id,
range,
&client,
nullptr,
&stats,
args.filter_id
};
// Setup an output buffer to compose the response. This has to be at least
// the worst-case size of a matrix event (64_KiB) or bad things happen.
const unique_buffer<mutable_buffer> buffer
@ -105,25 +117,19 @@ ircd::m::sync::handle_get(client &client,
size_t(buffer_size)
};
// Setup a chunked encoded response.
// Start the chunked encoded response.
resource::response::chunked response
{
client, http::OK
client, http::OK, 0
};
// Keep state for statistics of this sync here on the stack.
stats stats;
data data
json::stack out
{
request.user_id,
range,
buffer,
std::bind(&sync::flush, std::ref(data), std::ref(response), ph::_1),
size_t(flush_hiwat),
&client,
&stats,
args.filter_id
size_t(flush_hiwat)
};
data.out = &out;
log::debug
{
@ -132,7 +138,7 @@ ircd::m::sync::handle_get(client &client,
json::stack::object object
{
data.out
*data.out
};
const bool shortpolled
@ -163,17 +169,17 @@ ircd::m::sync::empty_response(data &data)
// Empty objects added to output otherwise Riot b0rks.
json::stack::object
{
data.out, "rooms"
*data.out, "rooms"
};
json::stack::object
{
data.out, "presence"
*data.out, "presence"
};
json::stack::member
{
data.out, "next_batch", json::value
*data.out, "next_batch", json::value
{
lex_cast(data.range.second), json::STRING
}
@ -212,7 +218,7 @@ try
{
json::stack::checkpoint checkpoint
{
data.out
*data.out
};
bool ret{false};
@ -221,12 +227,12 @@ try
{
json::stack::checkpoint checkpoint
{
data.out
*data.out
};
json::stack::object object
{
data.out, item.member_name()
*data.out, item.member_name()
};
if(item.polylog(data))
@ -240,7 +246,7 @@ try
if(ret)
json::stack::member
{
data.out, "next_batch", json::value
*data.out, "next_batch", json::value
{
lex_cast(data.range.second), json::STRING
}

View file

@ -42,7 +42,7 @@ ircd::m::sync::account_data_polylog(data &data)
{
json::stack::array array
{
data.out, "events"
*data.out, "events"
};
static const m::event::fetch::opts fopts
@ -82,19 +82,19 @@ ircd::m::sync::account_data_(data &data,
// Each account_data event is an object in the events array
json::stack::object object
{
data.out
*data.out
};
// type
json::stack::member
{
data.out, "type", at<"state_key"_>(event)
*data.out, "type", at<"state_key"_>(event)
};
// content
json::stack::member
{
data.out, "content", at<"content"_>(event)
*data.out, "content", at<"content"_>(event)
};
return true;

View file

@ -41,12 +41,12 @@ ircd::m::sync::device_lists_polylog(data &data)
{
json::stack::array
{
data.out, "changed"
*data.out, "changed"
};
json::stack::array
{
data.out, "left"
*data.out, "left"
};
return false;

View file

@ -16,10 +16,7 @@ IRCD_MODULE
namespace ircd::m::sync
{
static bool presence_polylog_events(data &);
static bool presence_polylog(data &);
static bool presence_linear_events(data &);
static bool presence_linear(data &);
extern item presence;
@ -37,33 +34,39 @@ bool
ircd::m::sync::presence_linear(data &data)
{
assert(data.event);
const m::event &event
{
*data.event
};
const m::event &event{*data.event};
if(json::get<"type"_>(event) != "ircd.presence")
return false;
if(json::get<"sender"_>(event) != m::me.user_id)
if(!my_host(json::get<"origin"_>(event)))
return false;
json::stack::array array
{
*data.out, "events"
};
json::stack::object object
{
*data.out
};
// sender
json::stack::member
{
data.out, "sender", unquote(at<"content"_>(event).get("user_id"))
*data.out, "sender", unquote(at<"content"_>(event).get("user_id"))
};
// type
json::stack::member
{
data.out, "type", json::value{"m.presence"}
*data.out, "type", json::value{"m.presence"}
};
// content
json::stack::member
{
data.out, "content", at<"content"_>(event)
*data.out, "content", at<"content"_>(event)
};
return true;
@ -71,16 +74,10 @@ ircd::m::sync::presence_linear(data &data)
bool
ircd::m::sync::presence_polylog(data &data)
{
return presence_polylog_events(data);
}
bool
ircd::m::sync::presence_polylog_events(data &data)
{
json::stack::array array
{
data.out, "events"
*data.out, "events"
};
bool ret{false};

View file

@ -75,7 +75,7 @@ ircd::m::sync::_rooms_linear(data &data,
{
json::stack::object object
{
data.out, item.member_name()
*data.out, item.member_name()
};
ret |= item.linear(data);
@ -107,12 +107,12 @@ ircd::m::sync::_rooms_polylog(data &data,
json::stack::checkpoint checkpoint
{
data.out
*data.out
};
json::stack::object object
{
data.out, membership
*data.out, membership
};
bool ret{false};
@ -162,12 +162,12 @@ ircd::m::sync::_rooms_polylog_room(data &data,
json::stack::checkpoint checkpoint
{
data.out
*data.out
};
json::stack::object object
{
data.out, room.room_id
*data.out, room.room_id
};
const event::idx room_head
@ -186,12 +186,12 @@ ircd::m::sync::_rooms_polylog_room(data &data,
{
json::stack::checkpoint checkpoint
{
data.out
*data.out
};
json::stack::object object
{
data.out, item.member_name()
*data.out, item.member_name()
};
if(item.polylog(data))

View file

@ -41,7 +41,7 @@ ircd::m::sync::room_account_data_polylog_events(data &data)
{
json::stack::array array
{
data.out, "events"
*data.out, "events"
};
assert(data.room);
@ -78,7 +78,7 @@ ircd::m::sync::room_account_data_polylog_events_event(data &data,
{
json::stack::object object
{
data.out
*data.out
};
json::stack::member

View file

@ -47,7 +47,7 @@ ircd::m::sync::rooms_ephemeral_events_polylog(data &data)
{
json::stack::array array
{
data.out, "events"
*data.out, "events"
};
bool ret{false};
@ -56,7 +56,7 @@ ircd::m::sync::rooms_ephemeral_events_polylog(data &data)
{
json::stack::checkpoint checkpoint
{
data.out
*data.out
};
if(item.polylog(data))

View file

@ -105,7 +105,7 @@ ircd::m::sync::_handle_message_receipt(data &data,
json::stack::object object
{
data.out
*data.out
};
// type

View file

@ -92,7 +92,7 @@ ircd::m::sync::room_state_polylog_events(data &data)
const m::room::state state{room};
json::stack::array array
{
data.out, "events"
*data.out, "events"
};
bool ret{false};

View file

@ -54,7 +54,7 @@ ircd::m::sync::room_timeline_linear(data &data)
{
json::stack::object object
{
data.out
*data.out
};
m::room room;
@ -88,7 +88,7 @@ ircd::m::sync::_room_timeline_linear_events(data &data,
{
json::stack::array array
{
data.out, "events"
*data.out, "events"
};
return {};
@ -111,13 +111,13 @@ ircd::m::sync::room_timeline_polylog(data &data)
// prev_batch
json::stack::member
{
data.out, "prev_batch", string_view{prev}
*data.out, "prev_batch", string_view{prev}
};
// limited
json::stack::member
{
data.out, "limited", json::value{limited}
*data.out, "limited", json::value{limited}
};
return ret;
@ -136,7 +136,7 @@ ircd::m::sync::_room_timeline_polylog_events(data &data,
json::stack::array array
{
data.out, "events"
*data.out, "events"
};
// messages seeks to the newest event, but the client wants the oldest

View file

@ -56,7 +56,7 @@ ircd::m::sync::room_unread_notifications_polylog(data &data)
// highlight_count
json::stack::member
{
data.out, "highlight_count", json::value
*data.out, "highlight_count", json::value
{
_highlight_count(room, data.user, start_idx, data.range.second)
}
@ -65,7 +65,7 @@ ircd::m::sync::room_unread_notifications_polylog(data &data)
// notification_count
json::stack::member
{
data.out, "notification_count", json::value
*data.out, "notification_count", json::value
{
_notification_count(room, start_idx, data.range.second)
}

View file

@ -41,7 +41,7 @@ ircd::m::sync::to_device_polylog(data &data)
{
json::stack::array array
{
data.out, "events"
*data.out, "events"
};
const m::room &user_room