2018-12-01 23:55:15 +01:00
|
|
|
// 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_EVENT_FETCH_H
|
|
|
|
|
2019-01-16 21:12:59 +01:00
|
|
|
/// Event Fetcher (local).
|
|
|
|
///
|
|
|
|
/// Fetches event data from the local database and populates an m::event which
|
|
|
|
/// is a parent of this class; an instance of this object can be used as an
|
|
|
|
/// `m::event` via that upcast. The data backing this `m::event` is a zero-copy
|
|
|
|
/// reference into the database and its lifetime is governed by the internals
|
|
|
|
/// of this object.
|
|
|
|
///
|
|
|
|
/// This can be constructed from either an event::idx or an `event_id`; the
|
|
|
|
/// latter will incur an extra m::index() lookup. The constructor will throw
|
|
|
|
/// for a missing event; the nothrow overloads will set a boolean indicator
|
|
|
|
/// instead. A default constructor can also be used; after construction the
|
|
|
|
/// seek() ADL suite can be used to the above effect.
|
|
|
|
///
|
|
|
|
/// The data is populated by one of two query types to the database; this is
|
|
|
|
/// determined automatically by default, but can be configured further with
|
|
|
|
/// the options structure.
|
|
|
|
///
|
2018-12-01 23:55:15 +01:00
|
|
|
struct ircd::m::event::fetch
|
|
|
|
:event
|
|
|
|
{
|
|
|
|
struct opts;
|
2019-01-15 21:49:53 +01:00
|
|
|
|
2018-12-01 23:55:15 +01:00
|
|
|
using keys = event::keys;
|
2019-01-15 21:49:53 +01:00
|
|
|
using view_closure = std::function<void (const string_view &)>;
|
2018-12-01 23:55:15 +01:00
|
|
|
|
|
|
|
static const opts default_opts;
|
|
|
|
|
|
|
|
std::array<db::cell, event::size()> cell;
|
2019-01-15 23:46:35 +01:00
|
|
|
db::cell _json;
|
2018-12-01 23:55:15 +01:00
|
|
|
db::row row;
|
|
|
|
bool valid;
|
|
|
|
|
|
|
|
public:
|
2019-01-16 21:12:59 +01:00
|
|
|
fetch(const idx &, std::nothrow_t, const opts & = default_opts);
|
|
|
|
fetch(const id &, std::nothrow_t, const opts & = default_opts);
|
|
|
|
fetch(const id &, const opts & = default_opts);
|
|
|
|
fetch(const idx &, const opts & = default_opts);
|
|
|
|
fetch(const opts & = default_opts);
|
|
|
|
fetch(fetch &&) = delete;
|
|
|
|
fetch(const fetch &) = delete;
|
2019-01-17 02:53:47 +01:00
|
|
|
fetch &operator=(fetch &&) = delete;
|
2019-01-16 21:12:59 +01:00
|
|
|
fetch &operator=(const fetch &) = delete;
|
2018-12-01 23:55:15 +01:00
|
|
|
|
|
|
|
static bool event_id(const idx &, std::nothrow_t, const id::closure &);
|
|
|
|
static void event_id(const idx &, const id::closure &);
|
|
|
|
};
|
|
|
|
|
2019-01-15 23:46:35 +01:00
|
|
|
namespace ircd::m
|
|
|
|
{
|
2019-01-16 21:12:59 +01:00
|
|
|
bool seek(event::fetch &, const event::idx &, std::nothrow_t, const event::fetch::opts & = event::fetch::default_opts);
|
|
|
|
void seek(event::fetch &, const event::idx &, const event::fetch::opts & = event::fetch::default_opts);
|
2019-01-15 23:46:35 +01:00
|
|
|
|
2019-01-16 21:12:59 +01:00
|
|
|
bool seek(event::fetch &, const event::id &, std::nothrow_t, const event::fetch::opts & = event::fetch::default_opts);
|
|
|
|
void seek(event::fetch &, const event::id &, const event::fetch::opts & = event::fetch::default_opts);
|
2019-01-15 23:46:35 +01:00
|
|
|
}
|
|
|
|
|
2019-01-16 21:12:59 +01:00
|
|
|
/// Event Fetch Options.
|
|
|
|
///
|
|
|
|
/// Refer to the individual member documentations for details. Notes:
|
|
|
|
///
|
|
|
|
/// - The default keys selection is *all keys*. This is unnecessarily
|
|
|
|
/// expensive I/O for most uses of event::fetch; consider narrowing the keys
|
|
|
|
/// selection based on what properties of the `m::event` will be accessed.
|
|
|
|
///
|
|
|
|
/// - Row Query: The event is populated by conducting a set of point lookups
|
|
|
|
/// for the selected keys. The point lookups are parallelized so the latency
|
|
|
|
/// of a lookup is only limited to the slowest key. The benefit of this type
|
|
|
|
/// is that very efficient I/O and caching can be conducted, but the cost is
|
|
|
|
/// that each lookup in the row occupies a hardware I/O lane which is a limited
|
|
|
|
/// resource shared by the whole system.
|
|
|
|
///
|
|
|
|
/// - JSON Query: The event is populated by conducting a single point lookup
|
|
|
|
/// to a database value containing the full JSON string of the event. This
|
|
|
|
/// query is made when all keys are selected. The benefit of this query is that
|
|
|
|
/// it only occupies one hardware I/O lane in contrast with the row query. The
|
|
|
|
/// cost is that the full event JSON is read from storage (up to 64_KiB) and
|
|
|
|
/// maintained in cache.
|
|
|
|
///
|
2018-12-01 23:55:15 +01:00
|
|
|
struct ircd::m::event::fetch::opts
|
|
|
|
{
|
2019-01-15 23:46:35 +01:00
|
|
|
/// Event property selector
|
2018-12-01 23:55:15 +01:00
|
|
|
event::keys keys;
|
2019-01-15 23:46:35 +01:00
|
|
|
|
|
|
|
/// Database get options passthru
|
2018-12-01 23:55:15 +01:00
|
|
|
db::gopts gopts;
|
|
|
|
|
2019-01-16 21:12:59 +01:00
|
|
|
/// Whether to allow querying the event_json to populate the event. A value
|
|
|
|
/// of true only allows this type of query to be made; a value of false
|
|
|
|
/// prevents this query from ever being made.
|
|
|
|
bool query_json {true};
|
2019-01-15 23:46:35 +01:00
|
|
|
|
2019-01-16 21:12:59 +01:00
|
|
|
/// Whether to force an attempt at populating the event from event_json
|
|
|
|
/// first, bypassing any decision-making. This is useful if a key selection
|
|
|
|
/// is used which would trigger a row query but the developer wants the
|
|
|
|
/// json query anyway.
|
|
|
|
bool query_json_force {false};
|
2019-01-15 23:46:35 +01:00
|
|
|
|
2018-12-01 23:55:15 +01:00
|
|
|
opts(const event::keys &, const db::gopts & = {});
|
|
|
|
opts(const event::keys::selection &, const db::gopts & = {});
|
|
|
|
opts(const db::gopts &, const event::keys::selection & = {});
|
|
|
|
opts() = default;
|
|
|
|
};
|