0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

presence: Remove user.away, replaced by a metadata entry.

Cache the metadata retrieval value where feasible for minimal performance impact.
This commit is contained in:
William Pitcock 2009-06-02 02:03:51 -05:00
parent df2688426d
commit 884b5d41c1
10 changed files with 23 additions and 37 deletions

View file

@ -92,7 +92,6 @@ struct User
{
rb_dlink_list channel; /* chain of channel pointer blocks */
rb_dlink_list invited; /* chain of invite pointer blocks */
char *away; /* pointer to away message */
int refcnt; /* Number of times this block is referenced */
char suser[NICKLEN+1];

View file

@ -744,6 +744,7 @@ static void
msg_client(int p_or_n, const char *command,
struct Client *source_p, struct Client *target_p, const char *text)
{
const char *awaymsg;
int do_floodcount = 0;
if(MyClient(source_p))
@ -788,9 +789,9 @@ msg_client(int p_or_n, const char *command,
return;
}
if(MyConnect(source_p) && (p_or_n != NOTICE) && target_p->user && target_p->user->away)
if(MyConnect(source_p) && (p_or_n != NOTICE) && target_p->user && (awaymsg = get_metadata(target_p, "away")) != NULL)
sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY),
target_p->name, target_p->user->away);
target_p->name, awaymsg);
if(MyClient(target_p))
{

View file

@ -78,7 +78,7 @@ m_away(struct Client *client_p, struct Client *source_p, int parc, const char *p
if(parc < 2 || EmptyString(parv[1]))
{
/* Marking as not away */
if(source_p->user->away != NULL)
if(get_metadata(source_p, "away") != NULL)
{
/* we now send this only if they were away before --is */
sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
@ -90,17 +90,9 @@ m_away(struct Client *client_p, struct Client *source_p, int parc, const char *p
return 0;
}
if(source_p->user->away == NULL)
{
allocate_away(source_p);
rb_strlcpy(source_p->user->away, parv[1], AWAYLEN);
sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
":%s AWAY :%s", use_id(source_p), source_p->user->away);
} else {
rb_strlcpy(source_p->user->away, parv[1], AWAYLEN);
}
set_metadata(source_p, "away", parv[1]);
sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
":%s AWAY :%s", use_id(source_p), parv[1]);
if(MyConnect(source_p))
sendto_one_numeric(source_p, RPL_NOWAWAY, form_str(RPL_NOWAWAY));

View file

@ -58,6 +58,7 @@ static void add_invite(struct Channel *, struct Client *);
static int
m_invite(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
const char *awaymsg;
struct Client *target_p;
struct Channel *chptr;
struct membership *msptr;
@ -165,9 +166,9 @@ m_invite(struct Client *client_p, struct Client *source_p, int parc, const char
sendto_one(source_p, form_str(RPL_INVITING),
me.name, source_p->name,
target_p->name, parv[2]);
if(target_p->user->away)
if((awaymsg = get_metadata(target_p, "away")) != NULL)
sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY),
target_p->name, target_p->user->away);
target_p->name, awaymsg);
}
/* invite timestamp */
else if(parc > 3 && !EmptyString(parv[3]))

View file

@ -704,7 +704,7 @@ stats_operedup (struct Client *source_p)
if(IsOperInvis(target_p) && !IsOper(source_p))
continue;
if(target_p->user->away)
if(get_metadata(target_p, "away"))
continue;
count++;
@ -1137,7 +1137,6 @@ stats_memory (struct Client *source_p)
int conf_count = 0; /* conf lines */
int users_invited_count = 0; /* users invited */
int user_channels = 0; /* users in channels */
int aways_counted = 0;
size_t number_servers_cached; /* number of servers cached by scache */
size_t channel_memory = 0;
@ -1146,7 +1145,6 @@ stats_memory (struct Client *source_p)
size_t channel_invex_memory = 0;
size_t channel_quiet_memory = 0;
size_t away_memory = 0; /* memory used by aways */
size_t ww = 0; /* whowas array count */
size_t wwm = 0; /* whowas array memory used */
size_t conf_memory = 0; /* memory used by conf lines */
@ -1181,11 +1179,6 @@ stats_memory (struct Client *source_p)
users_counted++;
users_invited_count += rb_dlink_list_length(&target_p->user->invited);
user_channels += rb_dlink_list_length(&target_p->user->channel);
if(target_p->user->away)
{
aways_counted++;
away_memory += (strlen(target_p->user->away) + 1);
}
}
}
@ -1246,10 +1239,9 @@ stats_memory (struct Client *source_p)
(unsigned long) users_invited_count * sizeof(rb_dlink_node));
sendto_one_numeric(source_p, RPL_STATSDEBUG,
"z :User channels %u(%lu) Aways %u(%d)",
"z :User channels %u(%lu)",
user_channels,
(unsigned long) user_channels * sizeof(rb_dlink_node),
aways_counted, (int) away_memory);
(unsigned long) user_channels * sizeof(rb_dlink_node));
sendto_one_numeric(source_p, RPL_STATSDEBUG,
"z :Attached confs %u(%lu)",

View file

@ -84,7 +84,7 @@ m_userhost(struct Client *client_p, struct Client *source_p, int parc, const cha
rl = rb_sprintf(response, "%s%s=%c%s@%s ",
target_p->name,
IsOper(target_p) ? "*" : "",
(target_p->user->away) ? '-' : '+',
(get_metadata(target_p, "away") != NULL) ? '-' : '+',
target_p->username,
target_p->sockhost);
}
@ -93,7 +93,7 @@ m_userhost(struct Client *client_p, struct Client *source_p, int parc, const cha
rl = rb_sprintf(response, "%s%s=%c%s@%s ",
target_p->name,
IsOper(target_p) ? "*" : "",
(target_p->user->away) ? '-' : '+',
(get_metadata(target_p, "away") != NULL) ? '-' : '+',
target_p->username, target_p->host);
}

View file

@ -467,7 +467,7 @@ do_who(struct Client *source_p, struct Client *target_p, struct membership *mspt
const char *q;
rb_sprintf(status, "%c%s%s",
target_p->user->away ? 'G' : 'H', IsOper(target_p) ? "*" : "", msptr ? find_channel_status(msptr, fmt->fields || IsCapable(source_p, CLICAP_MULTI_PREFIX)) : "");
(get_metadata(target_p, "away") != NULL) ? 'G' : 'H', IsOper(target_p) ? "*" : "", msptr ? find_channel_status(msptr, fmt->fields || IsCapable(source_p, CLICAP_MULTI_PREFIX)) : "");
if (fmt->fields == 0)
sendto_one(source_p, form_str(RPL_WHOREPLY), me.name,

View file

@ -228,6 +228,7 @@ do_whois(struct Client *client_p, struct Client *source_p, int parc, const char
static void
single_whois(struct Client *source_p, struct Client *target_p, int operspy)
{
const char *awaymsg;
char buf[BUFSIZE];
rb_dlink_node *ptr;
struct membership *msptr;
@ -304,9 +305,9 @@ single_whois(struct Client *source_p, struct Client *target_p, int operspy)
target_p->name, target_p->servptr->name,
target_p->servptr->info);
if(target_p->user->away)
if((awaymsg = get_metadata(target_p, "away")) != NULL)
sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY),
target_p->name, target_p->user->away);
target_p->name, awaymsg);
if(IsOper(target_p))
{

View file

@ -1701,8 +1701,6 @@ free_user(struct User *user, struct Client *client_p)
{
if(--user->refcnt <= 0)
{
if(user->away)
rb_free((char *) user->away);
/*
* sanity check
*/

View file

@ -474,6 +474,8 @@ burst_TS6(struct Client *client_p)
RB_DLINK_FOREACH(ptr, global_client_list.head)
{
const char *awaymsg = NULL;
target_p = ptr->data;
if(!IsPerson(target_p))
@ -516,10 +518,10 @@ burst_TS6(struct Client *client_p)
use_id(target_p), target_p->user->suser);
}
if(ConfigFileEntry.burst_away && !EmptyString(target_p->user->away))
if(ConfigFileEntry.burst_away && (awaymsg = get_metadata(target_p, "away")) != NULL)
sendto_one(client_p, ":%s AWAY :%s",
use_id(target_p),
target_p->user->away);
awaymsg);
hclientinfo.target = target_p;
call_hook(h_burst_client, &hclientinfo);