mirror of
https://github.com/matrix-construct/construct
synced 2024-05-28 15:53:46 +02:00
ircd:Ⓜ️:room: Rename room::content to room::iterate and abstract.
This commit is contained in:
parent
9cb3bf2c28
commit
e7cf7ab0fc
|
@ -1,7 +1,7 @@
|
||||||
// The Construct
|
// The Construct
|
||||||
//
|
//
|
||||||
// Copyright (C) The Construct Developers, Authors & Contributors
|
// 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
|
// Permission to use, copy, modify, and/or distribute this software for any
|
||||||
// purpose with or without fee is hereby granted, provided that the above
|
// 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.
|
// full license for this software is available in the LICENSE file.
|
||||||
|
|
||||||
#pragma once
|
#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 entry = pair<uint64_t, m::event::idx>;
|
||||||
using closure = util::function_bool
|
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;
|
static conf::item<size_t> prefetch;
|
||||||
|
|
||||||
m::room room;
|
m::room room;
|
||||||
|
string_view column;
|
||||||
std::pair<uint64_t, int64_t> range; // highest (inclusive) to lowest (exclusive)
|
std::pair<uint64_t, int64_t> range; // highest (inclusive) to lowest (exclusive)
|
||||||
size_t queue_max;
|
size_t queue_max;
|
||||||
std::unique_ptr<entry[]> buf;
|
std::unique_ptr<entry[]> buf;
|
||||||
|
@ -32,17 +32,20 @@ struct ircd::m::room::content
|
||||||
public:
|
public:
|
||||||
bool for_each(const closure &) const;
|
bool for_each(const closure &) const;
|
||||||
|
|
||||||
content(const m::room &,
|
iterate(const m::room &,
|
||||||
const decltype(range) & = { -1UL, -1L });
|
const string_view &column = {},
|
||||||
|
const decltype(range) & = { -1UL, -1L });
|
||||||
|
|
||||||
content(const content &) = delete;
|
iterate(const iterate &) = delete;
|
||||||
content(content &&) = delete;
|
iterate(iterate &&) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline
|
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)
|
const decltype(range) &range)
|
||||||
:room{room}
|
:room{room}
|
||||||
|
,column{column}
|
||||||
,range{range}
|
,range{range}
|
||||||
,queue_max{prefetch}
|
,queue_max{prefetch}
|
||||||
,buf
|
,buf
|
|
@ -112,6 +112,7 @@ namespace ircd::m
|
||||||
struct ircd::m::room
|
struct ircd::m::room
|
||||||
{
|
{
|
||||||
struct events;
|
struct events;
|
||||||
|
struct iterate;
|
||||||
struct missing;
|
struct missing;
|
||||||
struct horizon;
|
struct horizon;
|
||||||
struct sounding;
|
struct sounding;
|
||||||
|
@ -128,7 +129,6 @@ struct ircd::m::room
|
||||||
struct message;
|
struct message;
|
||||||
struct messages;
|
struct messages;
|
||||||
struct bootstrap;
|
struct bootstrap;
|
||||||
struct content;
|
|
||||||
struct purge;
|
struct purge;
|
||||||
|
|
||||||
using id = m::id::room;
|
using id = m::id::room;
|
||||||
|
@ -195,6 +195,7 @@ struct ircd::m::room
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "events.h"
|
#include "events.h"
|
||||||
|
#include "iterate.h"
|
||||||
#include "sounding.h"
|
#include "sounding.h"
|
||||||
#include "missing.h"
|
#include "missing.h"
|
||||||
#include "horizon.h"
|
#include "horizon.h"
|
||||||
|
@ -205,7 +206,6 @@ struct ircd::m::room
|
||||||
#include "members.h"
|
#include "members.h"
|
||||||
#include "origins.h"
|
#include "origins.h"
|
||||||
#include "type.h"
|
#include "type.h"
|
||||||
#include "content.h"
|
|
||||||
#include "head.h"
|
#include "head.h"
|
||||||
#include "head_generate.h"
|
#include "head_generate.h"
|
||||||
#include "head_fetch.h"
|
#include "head_fetch.h"
|
||||||
|
|
|
@ -114,6 +114,7 @@ libircd_matrix_la_SOURCES += room_missing.cc
|
||||||
libircd_matrix_la_SOURCES += room_horizon.cc
|
libircd_matrix_la_SOURCES += room_horizon.cc
|
||||||
libircd_matrix_la_SOURCES += room_head.cc
|
libircd_matrix_la_SOURCES += room_head.cc
|
||||||
libircd_matrix_la_SOURCES += room_head_fetch.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_state_fetch.cc
|
||||||
libircd_matrix_la_SOURCES += room_join.cc
|
libircd_matrix_la_SOURCES += room_join.cc
|
||||||
libircd_matrix_la_SOURCES += room_leave.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_members.cc
|
||||||
libircd_matrix_la_SOURCES += room_origins.cc
|
libircd_matrix_la_SOURCES += room_origins.cc
|
||||||
libircd_matrix_la_SOURCES += room_type.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_message.cc
|
||||||
libircd_matrix_la_SOURCES += room_messages.cc
|
libircd_matrix_la_SOURCES += room_messages.cc
|
||||||
libircd_matrix_la_SOURCES += room_power.cc
|
libircd_matrix_la_SOURCES += room_power.cc
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
// The Construct
|
// The Construct
|
||||||
//
|
//
|
||||||
// Copyright (C) The Construct Developers, Authors & Contributors
|
// 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
|
// Permission to use, copy, modify, and/or distribute this software for any
|
||||||
// purpose with or without fee is hereby granted, provided that the above
|
// purpose with or without fee is hereby granted, provided that the above
|
||||||
// copyright notice and this permission notice is present in all copies. The
|
// copyright notice and this permission notice is present in all copies. The
|
||||||
// full license for this software is available in the LICENSE file.
|
// full license for this software is available in the LICENSE file.
|
||||||
|
|
||||||
decltype(ircd::m::room::content::prefetch)
|
decltype(ircd::m::room::iterate::prefetch)
|
||||||
ircd::m::room::content::prefetch
|
ircd::m::room::iterate::prefetch
|
||||||
{
|
{
|
||||||
{ "name", "ircd.m.room.content.prefetch" },
|
{ "name", "ircd.m.room.iterate.prefetch" },
|
||||||
{ "default", 512L },
|
{ "default", 512L },
|
||||||
};
|
};
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ircd::m::room::content::for_each(const closure &closure)
|
ircd::m::room::iterate::for_each(const closure &closure)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
entry *const __restrict__ queue
|
entry *const __restrict__ queue
|
||||||
|
@ -30,9 +30,9 @@ const
|
||||||
bool ret{true};
|
bool ret{true};
|
||||||
const auto call_user
|
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
|
// 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.
|
// 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
|
// After the user consumed the fetched entry, overwrite it with the
|
||||||
// next prefetch and continue the iteration.
|
// next prefetch and continue the iteration.
|
||||||
depth = it.depth();
|
depth = it.depth();
|
||||||
event_idx = it.event_idx();
|
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
|
// The primary loop completes when there's no more events left to
|
||||||
// prefetch, but another loop around the queue needs to be made for
|
// prefetch, but another loop around the queue needs to be made for
|
||||||
// any fetches still in flight.
|
// any fetches still in flight.
|
||||||
for(size_t j(i); ret && i < j + queue_max; ++i, pos = i % queue_max)
|
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;
|
return ret;
|
||||||
}
|
}
|
|
@ -396,9 +396,9 @@ ircd::m::search::query_room(result &result,
|
||||||
string_view{room_id},
|
string_view{room_id},
|
||||||
};
|
};
|
||||||
|
|
||||||
const m::room::content content
|
const m::room::iterate content
|
||||||
{
|
{
|
||||||
room
|
room, "content"
|
||||||
};
|
};
|
||||||
|
|
||||||
return content.for_each([&result, &query]
|
return content.for_each([&result, &query]
|
||||||
|
|
Loading…
Reference in a new issue