ircd:Ⓜ️:room: Rename room::content to room::iterate and abstract.

This commit is contained in:
Jason Volk 2023-02-21 19:47:25 -08:00
parent 9cb3bf2c28
commit e7cf7ab0fc
5 changed files with 29 additions and 26 deletions

View File

@ -1,7 +1,7 @@
// The Construct
//
// Copyright (C) The Construct Developers, Authors & Contributors
// Copyright (C) 2016-2020 Jason Volk <jason@zemos.net>
// Copyright (C) 2016-2023 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
@ -9,22 +9,22 @@
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_IRCD_M_ROOM_CONTENT_H
#define HAVE_IRCD_M_ROOM_ITERATE_H
/// Interfaced optimized for iterating the `content` of room events.
/// Interfaced optimized for pipelined iterations of room events.
///
struct ircd::m::room::content
struct ircd::m::room::iterate
{
using entry = pair<uint64_t, m::event::idx>;
using closure = util::function_bool
<
const json::object &, const uint64_t &, const event::idx &
const string_view, const uint64_t, const event::idx
>;
static const size_t prefetch_max;
static conf::item<size_t> prefetch;
m::room room;
string_view column;
std::pair<uint64_t, int64_t> range; // highest (inclusive) to lowest (exclusive)
size_t queue_max;
std::unique_ptr<entry[]> buf;
@ -32,17 +32,20 @@ struct ircd::m::room::content
public:
bool for_each(const closure &) const;
content(const m::room &,
const decltype(range) & = { -1UL, -1L });
iterate(const m::room &,
const string_view &column = {},
const decltype(range) & = { -1UL, -1L });
content(const content &) = delete;
content(content &&) = delete;
iterate(const iterate &) = delete;
iterate(iterate &&) = delete;
};
inline
ircd::m::room::content::content(const m::room &room,
ircd::m::room::iterate::iterate(const m::room &room,
const string_view &column,
const decltype(range) &range)
:room{room}
,column{column}
,range{range}
,queue_max{prefetch}
,buf

View File

@ -112,6 +112,7 @@ namespace ircd::m
struct ircd::m::room
{
struct events;
struct iterate;
struct missing;
struct horizon;
struct sounding;
@ -128,7 +129,6 @@ struct ircd::m::room
struct message;
struct messages;
struct bootstrap;
struct content;
struct purge;
using id = m::id::room;
@ -195,6 +195,7 @@ struct ircd::m::room
};
#include "events.h"
#include "iterate.h"
#include "sounding.h"
#include "missing.h"
#include "horizon.h"
@ -205,7 +206,6 @@ struct ircd::m::room
#include "members.h"
#include "origins.h"
#include "type.h"
#include "content.h"
#include "head.h"
#include "head_generate.h"
#include "head_fetch.h"

View File

@ -114,6 +114,7 @@ libircd_matrix_la_SOURCES += room_missing.cc
libircd_matrix_la_SOURCES += room_horizon.cc
libircd_matrix_la_SOURCES += room_head.cc
libircd_matrix_la_SOURCES += room_head_fetch.cc
libircd_matrix_la_SOURCES += room_iterate.cc
libircd_matrix_la_SOURCES += room_state_fetch.cc
libircd_matrix_la_SOURCES += room_join.cc
libircd_matrix_la_SOURCES += room_leave.cc
@ -121,7 +122,6 @@ libircd_matrix_la_SOURCES += room_visible.cc
libircd_matrix_la_SOURCES += room_members.cc
libircd_matrix_la_SOURCES += room_origins.cc
libircd_matrix_la_SOURCES += room_type.cc
libircd_matrix_la_SOURCES += room_content.cc
libircd_matrix_la_SOURCES += room_message.cc
libircd_matrix_la_SOURCES += room_messages.cc
libircd_matrix_la_SOURCES += room_power.cc

View File

@ -1,22 +1,22 @@
// The Construct
//
// Copyright (C) The Construct Developers, Authors & Contributors
// Copyright (C) 2016-2020 Jason Volk <jason@zemos.net>
// Copyright (C) 2016-2023 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
decltype(ircd::m::room::content::prefetch)
ircd::m::room::content::prefetch
decltype(ircd::m::room::iterate::prefetch)
ircd::m::room::iterate::prefetch
{
{ "name", "ircd.m.room.content.prefetch" },
{ "name", "ircd.m.room.iterate.prefetch" },
{ "default", 512L },
};
bool
ircd::m::room::content::for_each(const closure &closure)
ircd::m::room::iterate::for_each(const closure &closure)
const
{
entry *const __restrict__ queue
@ -30,9 +30,9 @@ const
bool ret{true};
const auto call_user
{
[&closure, &queue, &pos, &ret](const json::object &content)
[&closure, &queue, &pos, &ret](const string_view &val)
{
ret = closure(content, queue[pos].first, queue[pos].second);
ret = closure(val, queue[pos].first, queue[pos].second);
}
};
@ -48,20 +48,20 @@ const
// Fetch the content for the event at the current queue pos; this will
// be a no-op on the first iteration when the entries are all zero.
m::get(std::nothrow, event_idx, "content", call_user);
m::get(std::nothrow, event_idx, column, call_user);
// After the user consumed the fetched entry, overwrite it with the
// next prefetch and continue the iteration.
depth = it.depth();
event_idx = it.event_idx();
m::prefetch(event_idx, "content");
m::prefetch(event_idx, column);
}
// The primary loop completes when there's no more events left to
// prefetch, but another loop around the queue needs to be made for
// any fetches still in flight.
for(size_t j(i); ret && i < j + queue_max; ++i, pos = i % queue_max)
m::get(std::nothrow, queue[pos].second, "content", call_user);
m::get(std::nothrow, queue[pos].second, column, call_user);
return ret;
}

View File

@ -396,9 +396,9 @@ ircd::m::search::query_room(result &result,
string_view{room_id},
};
const m::room::content content
const m::room::iterate content
{
room
room, "content"
};
return content.for_each([&result, &query]