From 6831f195aa006459d6be8380355e5d3684676da6 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 5 Sep 2019 16:17:19 -0700 Subject: [PATCH] ircd::m::room::events: Add viewport metric concept; conf item. --- include/ircd/m/room/events.h | 11 +++++++++++ modules/m_room_events.cc | 38 +++++++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/include/ircd/m/room/events.h b/include/ircd/m/room/events.h index fdf683f74..a7b25bc78 100644 --- a/include/ircd/m/room/events.h +++ b/include/ircd/m/room/events.h @@ -11,6 +11,14 @@ #pragma once #define HAVE_IRCD_M_ROOM_EVENTS_H +// The "viewport" is comprised of events starting from the tophead (most recent +// in room timeline) and covering about ~20 events leading up to that. Note +// that this is a completely ad hoc and configurable server value. Events in +// the viewport must be eval'ed and synced to clients in the order they will +// be displayed. Events not in the viewport are not /synced to clients and any +// client request provides event ordering: thus older events (backfills, etc) +// can be eval'ed without this constraint. +// // The "sounding" is the depth of the first gap. In any attempt to trace // the room timeline from the tophead to the m.room.create event: the sounding // is the [highest number] depth preventing that. @@ -24,6 +32,7 @@ namespace ircd::m { + std::pair viewport(const room &); std::pair sounding(const room &); // Last missing (one) std::pair twain(const room &); std::pair hazard(const room &); // First missing (one) @@ -43,6 +52,8 @@ struct ircd::m::room::events struct horizon; struct missing; + static conf::item viewport_size; + m::room room; db::domain::const_iterator it; event::fetch _event; diff --git a/modules/m_room_events.cc b/modules/m_room_events.cc index 82630dd50..f23c459f8 100644 --- a/modules/m_room_events.cc +++ b/modules/m_room_events.cc @@ -14,9 +14,41 @@ IRCD_MODULE "Matrix room library" }; -// -// tools -// +IRCD_MODULE_EXPORT_DATA +decltype(ircd::m::room::events::viewport_size) +ircd::m::room::events::viewport_size +{ + { "name", "ircd.m.room.events.viewport.size" }, + { "default", 24L }, +}; + +std::pair +IRCD_MODULE_EXPORT +ircd::m::viewport(const room &room) +{ + std::pair ret + { + -1, 0 + }; + + m::room::events it + { + room + }; + + const size_t &max + { + room::events::viewport_size + }; + + for(size_t i(0); it && i < max; --it, ++i) + { + ret.first = it.depth(); + ret.second = it.event_idx(); + } + + return ret; +} std::pair IRCD_MODULE_EXPORT