From 966e30ac3e3bac63b329126a1ca9d06a5e82e3c9 Mon Sep 17 00:00:00 2001 From: piaip Date: Thu, 17 Sep 2009 14:40:00 +0000 Subject: * refine pwcuExitSave again, prevent the initial query if possible. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4851 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/proto.h | 2 +- mbbsd/passwd.c | 111 ++++++++++++++++++++++++-------------------------------- mbbsd/talk.c | 2 +- mbbsd/user.c | 2 +- 4 files changed, 51 insertions(+), 66 deletions(-) diff --git a/include/proto.h b/include/proto.h index db785acc..a3e87a7a 100644 --- a/include/proto.h +++ b/include/proto.h @@ -721,7 +721,7 @@ int pwcuRegisterSetInfo (const char *rname, // non-important based variables (only save on exit) int pwcuSetSignature (unsigned char newsig); -int pwcuSetWaterballMode(unsigned int bm); +int pwcuSetPagerUIType (unsigned int uitype); int pwcuToggleSortBoard (); int pwcuToggleFriendList(); int pwcuToggleUserFlag (unsigned int mask); // not saved until pwcuSaveUserFlags diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index efa23f43..ab7fb86e 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -417,11 +417,19 @@ pwcuToggleFriendList() // non-important variables (only save on exit) +static char +pwcu_dirty; + int -pwcuSetWaterballMode(unsigned int bm) +pwcuSetPagerUIType (unsigned int uitype) { // XXX you MUST save this variable in pwcuExitSave(); - cuser.pager_ui_type = bm % PAGER_UI_TYPES; + uitype %= PAGER_UI_TYPES; + if (cuser.pager_ui_type != uitype) + { + pwcu_dirty = 1; + cuser.pager_ui_type = uitype; + } return 0; } @@ -429,7 +437,11 @@ int pwcuSetSignature(unsigned char newsig) { // XXX you MUST save this variable in pwcuExitSave(); - cuser.signature = newsig; + if (cuser.signature != newsig) + { + pwcu_dirty = 1; + cuser.signature = newsig; + } return 0; } @@ -450,6 +462,7 @@ int pwcuLoginSave () time4_t baseref = 0; struct tm baseref_tm = {0}; + // XXX one more read here... can we avoid it? PWCU_START(); // new host from 'fromhost' @@ -500,79 +513,51 @@ int pwcuLoginSave () int pwcuExitSave () { - int dirty = 0; - uint32_t uflag, uflag2, withme; - uint8_t invisible, pager, signature, pager_ui_type; - int32_t money; - - PWCU_START(); - - // XXX if PWCU_START uses sync_query, then money is - // already changed... however, maybe not a problem here, - // since every deumoney() should write difference. - - // save variables for dirty check - uflag = u.uflag; - uflag2 = u.uflag2; - - withme = u.withme; - pager = u.pager; - invisible = u.invisible; - - money = u.money; - signature = u.signature; - pager_ui_type = u.pager_ui_type; + // determine dirty + if (pwcu_dirty || + cuser.withme != currutmp->withme || + cuser.pager != currutmp->pager || + cuser.invisible != currutmp->invisible || + (memcmp(cuser.mind,currutmp->mind, sizeof(cuser.mind)) != 0) ) + { + // maybe dirty, let's work harder. + PWCU_START(); + pwcu_dirty = 1; - // configure new utmp values - u.withme = currutmp->withme; - u.pager = currutmp->pager; - u.invisible = currutmp->invisible; + // XXX we may work harder to determine if this is a real + // dirty cache, however maybe it's not that important. - u.signature = cuser.signature; - u.money = moneyof(usernum); - u.pager_ui_type = cuser.pager_ui_type; + // configure new utmp values + u.withme = currutmp->withme; + u.pager = currutmp->pager; + u.invisible = currutmp->invisible; + memcpy(u.mind, currutmp->mind, sizeof(u.mind)); // XXX u.mind is NOT NULL-terminated. - // XXX 當初設計的人把 mind 設計成非 NULL terminated 的... - // assert(sizeof(u.mind) == sizeof(currutmp->mind)); - if (memcmp(u.mind, currutmp->mind, sizeof(u.mind)) != 0) - { - memcpy(u.mind,currutmp->mind, sizeof(u.mind)); - dirty = 1; - } + // configure those changed by 'not important variables' API + u.signature = cuser.signature; + u.pager_ui_type = cuser.pager_ui_type; + // u.money = moneyof(usernum); // should be already updated by deumoney - // check dirty - if (!dirty && ( - uflag != u.uflag || - uflag2 != u.uflag2|| - withme != u.withme|| - pager != u.pager || - money != u.money || - pager_ui_type != u.pager_ui_type || - signature != u.signature|| - invisible != u.invisible)) - { - dirty = 1; +#ifdef DEBUG + log_filef("log/pwcu_exitsave.log", LOG_CREAT, "%-13s exit %s at %s\n", + cuser.userid, pwcu_dirty ? "DIRTY" : "CLEAN", Cdatelite(&now)); +#endif + PWCU_END(); + // XXX return 0 here (PWCU_END), following code is not executed. } - #ifdef DEBUG - log_filef("log/pwcu_exitsave.log", LOG_CREAT, - "%s exit %s at %s\n", u.userid, - dirty ? "DIRTY" : "CLEAN", - Cdatelite(&now)); + log_filef("log/pwcu_exitsave.log", LOG_CREAT, "%-13s exit %s at %s\n", + cuser.userid, pwcu_dirty ? "DIRTY" : "CLEAN", Cdatelite(&now)); #endif - - // no need to save data. - if (!dirty) - return 0; - - PWCU_END(); + return 0; } int pwcuReload () { - int r = passwd_sync_query(usernum, &cuser); // XXX TODO verify cuser structure? + int r = passwd_sync_query(usernum, &cuser); + pwcu_dirty = 0; return r; } diff --git a/mbbsd/talk.c b/mbbsd/talk.c index bbeb7c30..1144de63 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -3015,7 +3015,7 @@ userlist(void) if (HasUserPerm(PERM_LOGINOK)) { static const char *wm[PAGER_UI_TYPES] = {"一般", "進階", "未來"}; - pwcuSetWaterballMode((cuser.pager_ui_type +1) % PAGER_UI_TYPES_USER); + pwcuSetPagerUIType((cuser.pager_ui_type +1) % PAGER_UI_TYPES_USER); /* vmsg cannot support multi lines */ move(b_lines - 4, 0); clrtobot(); diff --git a/mbbsd/user.c b/mbbsd/user.c index 29951d77..c71cf6fe 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -499,7 +499,7 @@ void Customize(void) { case 0: { - pwcuSetWaterballMode((cuser.pager_ui_type +1) % PAGER_UI_TYPES_USER); + pwcuSetPagerUIType((cuser.pager_ui_type +1) % PAGER_UI_TYPES_USER); vmsg("修改水球模式後請正常離線再重新上線"); dirty = 1; } -- cgit v1.2.3