0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-15 14:31:11 +01:00

ircd:Ⓜ️:room::state: Change return value from event::id to event::idx for simple get().

This commit is contained in:
Jason Volk 2019-02-13 14:27:51 -08:00
parent 8b992917ab
commit 1a6d173a0b
4 changed files with 31 additions and 26 deletions

View file

@ -39,8 +39,10 @@ struct ircd::m::room::state
const event::fetch::opts *fopts {nullptr}; const event::fetch::opts *fopts {nullptr};
mutable bool _not_present {false}; // cached result of !present() mutable bool _not_present {false}; // cached result of !present()
// Check if this object is representing the present state or a past state.
bool present() const; bool present() const;
// Iterate the state
bool for_each(const types_bool &) const; bool for_each(const types_bool &) const;
void for_each(const types &) const; void for_each(const types &) const;
bool for_each(const string_view &type, const keys_bool &view) const; bool for_each(const string_view &type, const keys_bool &view) const;
@ -77,10 +79,8 @@ struct ircd::m::room::state
void get(const string_view &type, const string_view &state_key, const event::closure_idx &) const; void get(const string_view &type, const string_view &state_key, const event::closure_idx &) const;
void get(const string_view &type, const string_view &state_key, const event::id::closure &) const; void get(const string_view &type, const string_view &state_key, const event::id::closure &) const;
void get(const string_view &type, const string_view &state_key, const event::closure &) const; void get(const string_view &type, const string_view &state_key, const event::closure &) const;
event::idx get(std::nothrow_t, const string_view &type, const string_view &state_key = "") const;
// Fetch and return state event id event::idx get(const string_view &type, const string_view &state_key = "") const;
event::id::buf get(std::nothrow_t, const string_view &type, const string_view &state_key = "") const;
event::id::buf get(const string_view &type, const string_view &state_key = "") const;
// Initiate a database prefetch on the state to cache for future access. // Initiate a database prefetch on the state to cache for future access.
size_t prefetch(const string_view &type, const event::idx &start = 0, const event::idx &stop = 0) const; size_t prefetch(const string_view &type, const event::idx &start = 0, const event::idx &stop = 0) const;

View file

@ -893,32 +893,32 @@ ircd::m::room::state::state(const m::room &room,
{ {
} }
ircd::m::event::id::buf ircd::m::event::idx
ircd::m::room::state::get(const string_view &type, ircd::m::room::state::get(const string_view &type,
const string_view &state_key) const string_view &state_key)
const const
{ {
event::id::buf ret; event::idx ret;
get(type, state_key, event::id::closure{[&ret] get(type, state_key, event::closure_idx{[&ret]
(const event::id &event_id) (const event::idx &event_idx)
{ {
ret = event_id; ret = event_idx;
}}); }});
return ret; return ret;
} }
ircd::m::event::id::buf ircd::m::event::idx
ircd::m::room::state::get(std::nothrow_t, ircd::m::room::state::get(std::nothrow_t,
const string_view &type, const string_view &type,
const string_view &state_key) const string_view &state_key)
const const
{ {
event::id::buf ret; event::idx ret{0};
get(std::nothrow, type, state_key, event::id::closure{[&ret] get(std::nothrow, type, state_key, event::closure_idx{[&ret]
(const event::id &event_id) (const event::idx &event_idx)
{ {
ret = event_id; ret = event_idx;
}}); }});
return ret; return ret;

View file

@ -86,17 +86,22 @@ get__make_join(client &client,
room_id room_id
}; };
auto auth_event_id auto auth_event_idx
{ {
state.get(std::nothrow, "m.room.member", user_id) state.get(std::nothrow, "m.room.member", user_id)
}; };
if(!auth_event_id) if(!auth_event_idx)
auth_event_id = state.get("m.room.create"); auth_event_idx = state.get("m.room.create");
const auto auth_event_id
{
m::event_id(auth_event_idx)
};
const m::event::fetch aevf const m::event::fetch aevf
{ {
auth_event_id, std::nothrow auth_event_idx, std::nothrow
}; };
const json::value auth[] const json::value auth[]

View file

@ -319,14 +319,14 @@ is_complete(const m::room &room)
room room
}; };
const auto create_id const auto create_idx
{ {
state.get("m.room.create") state.get("m.room.create")
}; };
room::messages it room::messages it
{ {
room, create_id, &fopts room, create_idx, &fopts
}; };
int64_t depth(-1); int64_t depth(-1);
@ -386,7 +386,7 @@ state__rebuild_present(const m::room &room)
room room
}; };
const auto create_id const auto create_idx
{ {
state.get("m.room.create") state.get("m.room.create")
}; };
@ -398,7 +398,7 @@ state__rebuild_present(const m::room &room)
m::room::messages it m::room::messages it
{ {
room, create_id, &fopts room, create_idx, &fopts
}; };
if(!it) if(!it)
@ -440,7 +440,7 @@ state__rebuild_history(const m::room &room)
room room
}; };
const auto create_id const auto create_idx
{ {
state.get("m.room.create") state.get("m.room.create")
}; };
@ -452,7 +452,7 @@ state__rebuild_history(const m::room &room)
m::room::messages it m::room::messages it
{ {
room, create_id, &fopts room, create_idx, &fopts
}; };
if(!it) if(!it)
@ -607,7 +607,7 @@ head__rebuild(const m::room &room)
{ {
size_t ret{0}; size_t ret{0};
const m::room::state state{room}; const m::room::state state{room};
const auto create_id const auto create_idx
{ {
state.get("m.room.create") state.get("m.room.create")
}; };
@ -619,7 +619,7 @@ head__rebuild(const m::room &room)
m::room::messages it m::room::messages it
{ {
room, create_id, &fopts room, create_idx, &fopts
}; };
if(!it) if(!it)