mirror of
https://github.com/matrix-construct/construct
synced 2024-12-27 07:54:05 +01:00
ircd:Ⓜ️ Split events iterations into namespace.
This commit is contained in:
parent
5a3f105afc
commit
7f3919dd17
6 changed files with 131 additions and 98 deletions
26
include/ircd/m/events.h
Normal file
26
include/ircd/m/events.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
// Matrix Construct
|
||||
//
|
||||
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
||||
// Copyright (C) 2016-2018 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.
|
||||
|
||||
#pragma once
|
||||
#define HAVE_IRCD_M_EVENTS_H
|
||||
|
||||
namespace ircd::m::events
|
||||
{
|
||||
using id_closure_bool = std::function<bool (const event::idx &, const event::id &)>;
|
||||
using closure_bool = std::function<bool (const event::idx &, const event &)>;
|
||||
|
||||
// counts up from start
|
||||
bool for_each(const uint64_t &start, const id_closure_bool &);
|
||||
bool for_each(const uint64_t &start, const closure_bool &);
|
||||
|
||||
// -1 starts at newest event; counts down
|
||||
bool rfor_each(const uint64_t &start, const id_closure_bool &);
|
||||
bool rfor_each(const uint64_t &start, const closure_bool &);
|
||||
}
|
|
@ -61,6 +61,7 @@ namespace ircd
|
|||
#include "room.h"
|
||||
#include "user.h"
|
||||
#include "rooms.h"
|
||||
#include "events.h"
|
||||
#include "node.h"
|
||||
#include "login.h"
|
||||
#include "register.h"
|
||||
|
|
98
ircd/m/m.cc
98
ircd/m/m.cc
|
@ -922,6 +922,104 @@ ircd::m::node::room::room(const m::node &node)
|
|||
static_cast<m::room &>(*this) = room_id;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// m/events.h
|
||||
//
|
||||
|
||||
bool
|
||||
ircd::m::events::rfor_each(const uint64_t &start,
|
||||
const closure_bool &closure)
|
||||
{
|
||||
event::fetch event;
|
||||
return rfor_each(start, id_closure_bool{[&event, &closure]
|
||||
(const event::idx &event_idx, const event::id &event_id)
|
||||
{
|
||||
if(!seek(event, event_idx, std::nothrow))
|
||||
return true;
|
||||
|
||||
return closure(event_idx, event);
|
||||
}});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::events::rfor_each(const uint64_t &start,
|
||||
const id_closure_bool &closure)
|
||||
{
|
||||
static constexpr auto column_idx
|
||||
{
|
||||
json::indexof<event, "event_id"_>()
|
||||
};
|
||||
|
||||
auto &column
|
||||
{
|
||||
dbs::event_column.at(column_idx)
|
||||
};
|
||||
|
||||
if(start == uint64_t(-1))
|
||||
{
|
||||
for(auto it(column.rbegin()); it; ++it)
|
||||
if(!closure(byte_view<event::idx>(it->first), it->second))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
auto it
|
||||
{
|
||||
column.lower_bound(byte_view<string_view>(start))
|
||||
};
|
||||
|
||||
for(; it; ++it)
|
||||
if(!closure(byte_view<event::idx>(it->first), it->second))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::events::for_each(const uint64_t &start,
|
||||
const closure_bool &closure)
|
||||
{
|
||||
event::fetch event;
|
||||
return for_each(start, id_closure_bool{[&event, &closure]
|
||||
(const event::idx &event_idx, const event::id &event_id)
|
||||
{
|
||||
if(!seek(event, event_idx, std::nothrow))
|
||||
return true;
|
||||
|
||||
return closure(event_idx, event);
|
||||
}});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::events::for_each(const uint64_t &start,
|
||||
const id_closure_bool &closure)
|
||||
{
|
||||
static constexpr auto column_idx
|
||||
{
|
||||
json::indexof<event, "event_id"_>()
|
||||
};
|
||||
|
||||
auto &column
|
||||
{
|
||||
dbs::event_column.at(column_idx)
|
||||
};
|
||||
|
||||
auto it
|
||||
{
|
||||
start > 0?
|
||||
column.lower_bound(byte_view<string_view>(start)):
|
||||
column.begin()
|
||||
};
|
||||
|
||||
for(; it; ++it)
|
||||
if(!closure(byte_view<event::idx>(it->first), it->second))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// m/rooms.h
|
||||
|
|
93
ircd/m/vm.cc
93
ircd/m/vm.cc
|
@ -528,99 +528,6 @@ ircd::m::vm::write(eval &eval)
|
|||
txn();
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::vm::events::rfor_each(const uint64_t &start,
|
||||
const closure_bool &closure)
|
||||
{
|
||||
event::fetch event;
|
||||
return rfor_each(start, id_closure_bool{[&event, &closure]
|
||||
(const event::idx &event_idx, const event::id &event_id)
|
||||
{
|
||||
if(!seek(event, event_idx, std::nothrow))
|
||||
return true;
|
||||
|
||||
return closure(event_idx, event);
|
||||
}});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::vm::events::rfor_each(const uint64_t &start,
|
||||
const id_closure_bool &closure)
|
||||
{
|
||||
static constexpr auto column_idx
|
||||
{
|
||||
json::indexof<event, "event_id"_>()
|
||||
};
|
||||
|
||||
auto &column
|
||||
{
|
||||
dbs::event_column.at(column_idx)
|
||||
};
|
||||
|
||||
if(start == uint64_t(-1))
|
||||
{
|
||||
for(auto it(column.rbegin()); it; ++it)
|
||||
if(!closure(byte_view<event::idx>(it->first), it->second))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
auto it
|
||||
{
|
||||
column.lower_bound(byte_view<string_view>(start))
|
||||
};
|
||||
|
||||
for(; it; ++it)
|
||||
if(!closure(byte_view<event::idx>(it->first), it->second))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::vm::events::for_each(const uint64_t &start,
|
||||
const closure_bool &closure)
|
||||
{
|
||||
event::fetch event;
|
||||
return for_each(start, id_closure_bool{[&event, &closure]
|
||||
(const event::idx &event_idx, const event::id &event_id)
|
||||
{
|
||||
if(!seek(event, event_idx, std::nothrow))
|
||||
return true;
|
||||
|
||||
return closure(event_idx, event);
|
||||
}});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::vm::events::for_each(const uint64_t &start,
|
||||
const id_closure_bool &closure)
|
||||
{
|
||||
static constexpr auto column_idx
|
||||
{
|
||||
json::indexof<event, "event_id"_>()
|
||||
};
|
||||
|
||||
auto &column
|
||||
{
|
||||
dbs::event_column.at(column_idx)
|
||||
};
|
||||
|
||||
auto it
|
||||
{
|
||||
start > 0?
|
||||
column.lower_bound(byte_view<string_view>(start)):
|
||||
column.begin()
|
||||
};
|
||||
|
||||
for(; it; ++it)
|
||||
if(!closure(byte_view<event::idx>(it->first), it->second))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const uint64_t &
|
||||
ircd::m::vm::sequence(const eval &eval)
|
||||
{
|
||||
|
|
|
@ -187,7 +187,8 @@ try
|
|||
|
||||
std::map<std::string, std::vector<std::string>, std::less<>> r;
|
||||
|
||||
m::vm::events::for_each(since, [&]
|
||||
bool limited{false};
|
||||
m::events::for_each(since, [&]
|
||||
(const uint64_t &sequence, const m::event &event)
|
||||
{
|
||||
if(!r.empty() && (since - _since > 128))
|
||||
|
|
|
@ -1454,11 +1454,11 @@ console_cmd__key__fetch(opt &out, const string_view &line)
|
|||
}
|
||||
|
||||
//
|
||||
// vm
|
||||
// events
|
||||
//
|
||||
|
||||
bool
|
||||
console_cmd__vm__events(opt &out, const string_view &line)
|
||||
console_cmd__events(opt &out, const string_view &line)
|
||||
{
|
||||
const params param{line, " ",
|
||||
{
|
||||
|
@ -1475,7 +1475,7 @@ console_cmd__vm__events(opt &out, const string_view &line)
|
|||
param.at<size_t>(1, 32)
|
||||
};
|
||||
|
||||
m::vm::events::rfor_each(start, [&out, &limit]
|
||||
m::events::rfor_each(start, [&out, &limit]
|
||||
(const uint64_t &seq, const m::event &event)
|
||||
{
|
||||
out << seq << " " << pretty_oneline(event) << std::endl;;
|
||||
|
@ -1568,7 +1568,7 @@ console_cmd__event__dump(opt &out, const string_view &line)
|
|||
|
||||
char *pos{data(buf)};
|
||||
size_t foff{0}, ecount{0}, acount{0}, errcount{0};
|
||||
m::vm::events::for_each(0, [&](const uint64_t &seq, const m::event &event)
|
||||
m::events::for_each(0, [&](const uint64_t &seq, const m::event &event)
|
||||
{
|
||||
const auto remain
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue