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 25e664566f
commit 987ef7eb1f
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 channel; /* chain of channel pointer blocks */
rb_dlink_list invited; /* chain of invite 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 */ int refcnt; /* Number of times this block is referenced */
char suser[NICKLEN+1]; char suser[NICKLEN+1];

View File

@ -744,6 +744,7 @@ static void
msg_client(int p_or_n, const char *command, msg_client(int p_or_n, const char *command,
struct Client *source_p, struct Client *target_p, const char *text) struct Client *source_p, struct Client *target_p, const char *text)
{ {
const char *awaymsg;
int do_floodcount = 0; int do_floodcount = 0;
if(MyClient(source_p)) if(MyClient(source_p))
@ -788,9 +789,9 @@ msg_client(int p_or_n, const char *command,
return; 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), 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)) 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])) if(parc < 2 || EmptyString(parv[1]))
{ {
/* Marking as not away */ /* 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 */ /* we now send this only if they were away before --is */
sendto_server(client_p, NULL, CAP_TS6, NOCAPS, sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
@ -90,18 +90,10 @@ m_away(struct Client *client_p, struct Client *source_p, int parc, const char *p
return 0; return 0;
} }
set_metadata(source_p, "away", parv[1]);
if(source_p->user->away == NULL) sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
{ ":%s AWAY :%s", use_id(source_p), parv[1]);
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);
}
if(MyConnect(source_p)) if(MyConnect(source_p))
sendto_one_numeric(source_p, RPL_NOWAWAY, form_str(RPL_NOWAWAY)); 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 static int
m_invite(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) m_invite(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{ {
const char *awaymsg;
struct Client *target_p; struct Client *target_p;
struct Channel *chptr; struct Channel *chptr;
struct membership *msptr; 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), sendto_one(source_p, form_str(RPL_INVITING),
me.name, source_p->name, me.name, source_p->name,
target_p->name, parv[2]); 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), sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY),
target_p->name, target_p->user->away); target_p->name, awaymsg);
} }
/* invite timestamp */ /* invite timestamp */
else if(parc > 3 && !EmptyString(parv[3])) 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)) if(IsOperInvis(target_p) && !IsOper(source_p))
continue; continue;
if(target_p->user->away) if(get_metadata(target_p, "away"))
continue; continue;
count++; count++;
@ -1137,7 +1137,6 @@ stats_memory (struct Client *source_p)
int conf_count = 0; /* conf lines */ int conf_count = 0; /* conf lines */
int users_invited_count = 0; /* users invited */ int users_invited_count = 0; /* users invited */
int user_channels = 0; /* users in channels */ int user_channels = 0; /* users in channels */
int aways_counted = 0;
size_t number_servers_cached; /* number of servers cached by scache */ size_t number_servers_cached; /* number of servers cached by scache */
size_t channel_memory = 0; size_t channel_memory = 0;
@ -1146,7 +1145,6 @@ stats_memory (struct Client *source_p)
size_t channel_invex_memory = 0; size_t channel_invex_memory = 0;
size_t channel_quiet_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 ww = 0; /* whowas array count */
size_t wwm = 0; /* whowas array memory used */ size_t wwm = 0; /* whowas array memory used */
size_t conf_memory = 0; /* memory used by conf lines */ size_t conf_memory = 0; /* memory used by conf lines */
@ -1181,11 +1179,6 @@ stats_memory (struct Client *source_p)
users_counted++; users_counted++;
users_invited_count += rb_dlink_list_length(&target_p->user->invited); users_invited_count += rb_dlink_list_length(&target_p->user->invited);
user_channels += rb_dlink_list_length(&target_p->user->channel); 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)); (unsigned long) users_invited_count * sizeof(rb_dlink_node));
sendto_one_numeric(source_p, RPL_STATSDEBUG, sendto_one_numeric(source_p, RPL_STATSDEBUG,
"z :User channels %u(%lu) Aways %u(%d)", "z :User channels %u(%lu)",
user_channels, user_channels,
(unsigned long) user_channels * sizeof(rb_dlink_node), (unsigned long) user_channels * sizeof(rb_dlink_node));
aways_counted, (int) away_memory);
sendto_one_numeric(source_p, RPL_STATSDEBUG, sendto_one_numeric(source_p, RPL_STATSDEBUG,
"z :Attached confs %u(%lu)", "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 ", rl = rb_sprintf(response, "%s%s=%c%s@%s ",
target_p->name, target_p->name,
IsOper(target_p) ? "*" : "", IsOper(target_p) ? "*" : "",
(target_p->user->away) ? '-' : '+', (get_metadata(target_p, "away") != NULL) ? '-' : '+',
target_p->username, target_p->username,
target_p->sockhost); 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 ", rl = rb_sprintf(response, "%s%s=%c%s@%s ",
target_p->name, target_p->name,
IsOper(target_p) ? "*" : "", IsOper(target_p) ? "*" : "",
(target_p->user->away) ? '-' : '+', (get_metadata(target_p, "away") != NULL) ? '-' : '+',
target_p->username, target_p->host); 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; const char *q;
rb_sprintf(status, "%c%s%s", 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) if (fmt->fields == 0)
sendto_one(source_p, form_str(RPL_WHOREPLY), me.name, 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 static void
single_whois(struct Client *source_p, struct Client *target_p, int operspy) single_whois(struct Client *source_p, struct Client *target_p, int operspy)
{ {
const char *awaymsg;
char buf[BUFSIZE]; char buf[BUFSIZE];
rb_dlink_node *ptr; rb_dlink_node *ptr;
struct membership *msptr; 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->name, target_p->servptr->name,
target_p->servptr->info); 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), 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)) 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->refcnt <= 0)
{ {
if(user->away)
rb_free((char *) user->away);
/* /*
* sanity check * sanity check
*/ */

View File

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