0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-29 00:03:45 +02:00

modules/s_fetch: Minor reorg; pass room arg to fetch::synchronize().

This commit is contained in:
Jason Volk 2019-04-22 12:32:54 -07:00
parent 7d3ccb975a
commit f6314a4201
4 changed files with 82 additions and 44 deletions

View file

@ -27,7 +27,7 @@ namespace ircd::m::fetch
bool cancel(request &);
bool start(const m::room::id &, const m::event::id &);
bool prefetch(const m::room::id &, const m::event::id &);
bool synchronize(const m::room::id &);
bool synchronize(const m::room &);
// Composed operations
void auth_chain(const room &, const net::hostport &);

View file

@ -469,16 +469,16 @@ ircd::m::fetch::auth_chain(const room &r,
}
bool
ircd::m::fetch::synchronize(const m::room::id &room_id)
ircd::m::fetch::synchronize(const m::room &room)
{
using prototype = bool (const m::room::id &);
using prototype = bool (const m::room &);
static mods::import<prototype> call
{
"s_fetch", "ircd::m::fetch::synchronize"
};
return call(room_id);
return call(room);
}
bool

View file

@ -12528,19 +12528,50 @@ console_cmd__fetch(opt &out, const string_view &line)
m::room_id(param.at("room_id"))
};
if(!param["event_id"])
{
m::fetch::synchronize(room_id);
out << "done" << std::endl;
return true;
}
const m::event::id event_id
{
param.at("event_id")
};
m::fetch::start(room_id, event_id);
out << "in work..." << std::endl;
if(!m::fetch::start(room_id, event_id))
{
out << "failed to start." << std::endl;
return true;
}
out << "starting..." << std::endl;
return true;
}
bool
console_cmd__fetch__sync(opt &out, const string_view &line)
{
const params param{line, " ",
{
"room_id", "event_id"
}};
const auto room_id
{
m::room_id(param.at("room_id"))
};
const string_view &event_id
{
param["event_id"]
};
const m::room room
{
room_id, event_id
};
if(!m::fetch::synchronize(room))
{
out << "failed to start." << std::endl;
return true;
}
out << "done." << std::endl;
return true;
}

View file

@ -64,6 +64,29 @@ ircd::m::fetch::requests;
decltype(ircd::m::fetch::dock)
ircd::m::fetch::dock;
//
// init
//
void
ircd::m::fetch::init()
{
}
void
ircd::m::fetch::fini()
{
request_context.terminate();
eval_context.terminate();
request_context.join();
eval_context.join();
requests.clear();
complete.clear();
assert(requests.empty());
assert(complete.empty());
}
///////////////////////////////////////////////////////////////////////////////
//
// m/fetch.h
@ -76,6 +99,20 @@ namespace ircd::m::fetch
static void handle_state_ids(const m::room &, const m::feds::result &);
}
bool
IRCD_MODULE_EXPORT
ircd::m::fetch::synchronize(const m::room &room)
{
m::feds::opts opts;
opts.op = m::feds::op::head;
opts.room_id = room.room_id;
opts.event_id = room.event_id;
opts.nothrow_closure = true;
opts.closure_errors = false;
return true;
}
void
IRCD_MODULE_EXPORT
ircd::m::fetch::state_ids(const room &room)
@ -136,6 +173,7 @@ ircd::m::fetch::_heads(const m::feds::opts &opts_)
{
auto opts(opts_);
opts.op = m::feds::op::head;
std::map<std::string, size_t> heads;
m::feds::acquire(opts, [&heads]
(const auto &result)
@ -251,13 +289,6 @@ ircd::m::fetch::auth_chain(const room &room,
};
}
bool
IRCD_MODULE_EXPORT
ircd::m::fetch::synchronize(const m::room::id &room_id)
{
return true;
}
bool
IRCD_MODULE_EXPORT
ircd::m::fetch::prefetch(const m::room::id &room_id,
@ -308,30 +339,6 @@ ircd::m::fetch::for_each(const std::function<bool (request &)> &closure)
// s_fetch.h
//
//
// init
//
void
ircd::m::fetch::init()
{
}
void
ircd::m::fetch::fini()
{
request_context.terminate();
eval_context.terminate();
request_context.join();
eval_context.join();
requests.clear();
complete.clear();
assert(requests.empty());
assert(complete.empty());
}
//
// fetch_phase
//