summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-03-10 21:18:07 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-03-10 21:18:07 +0800
commitb9d50d84ccc8c070c7e38f2a9dcd1f3bb5641df5 (patch)
treee8272b4de36a873e61c40473f3b7c7a077b0500d
parentf63fd767f682e9eb4d5a2ca37c5884e4a5441b12 (diff)
downloadpttbbs-b9d50d84ccc8c070c7e38f2a9dcd1f3bb5641df5.tar
pttbbs-b9d50d84ccc8c070c7e38f2a9dcd1f3bb5641df5.tar.gz
pttbbs-b9d50d84ccc8c070c7e38f2a9dcd1f3bb5641df5.tar.bz2
pttbbs-b9d50d84ccc8c070c7e38f2a9dcd1f3bb5641df5.tar.lz
pttbbs-b9d50d84ccc8c070c7e38f2a9dcd1f3bb5641df5.tar.xz
pttbbs-b9d50d84ccc8c070c7e38f2a9dcd1f3bb5641df5.tar.zst
pttbbs-b9d50d84ccc8c070c7e38f2a9dcd1f3bb5641df5.zip
HOTBOARDCACHE
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1584 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--include/perm.h11
-rw-r--r--include/pttstruct.h2
-rw-r--r--mbbsd/board.c22
-rw-r--r--sample/pttbbs.conf5
-rw-r--r--util/shmctl.c34
5 files changed, 65 insertions, 9 deletions
diff --git a/include/perm.h b/include/perm.h
index bab82ae3..2d676bae 100644
--- a/include/perm.h
+++ b/include/perm.h
@@ -53,4 +53,15 @@
#define HAVE_PERM(x) (cuser.userlevel&(x))
#define PERM_HIDE(u) ((u)->userlevel & PERM_SYSOP && \
(u)->userlevel & PERM_DENYPOST)
+
+#define IS_BOARD(bptr) ((bptr)->brdname[0] && \
+ !((bptr)->brdattr & BRD_GROUPBOARD))
+#define IS_GROUP(bptr) ((bptr)->brdname[0] && \
+ ((bptr)->brdattr & BRD_GROUPBOARD))
+
+#define IS_OPENBRD(bptr) \
+ (!(((bptr)->brdattr & (BRD_HIDE | BRD_TOP)) || \
+ ((bptr)->level && !((bptr)->brdattr & BRD_POSTMASK) && \
+ ((bptr)->level & \
+ ~(PERM_BASIC|PERM_CHAT|PERM_PAGE|PERM_POST|PERM_LOGINOK)))))
#endif
diff --git a/include/pttstruct.h b/include/pttstruct.h
index 550b9437..34becd25 100644
--- a/include/pttstruct.h
+++ b/include/pttstruct.h
@@ -366,7 +366,7 @@ typedef struct {
boardheader_t bcache[MAX_BOARD];
boardheader_t *bsorted[2][MAX_BOARD]; /* 0: by name 1: by class */
#if HOTBOARDCACHE
- char nHOTs;
+ unsigned char nHOTs;
boardheader_t *HBcache[HOTBOARDCACHE];
#endif
#if DIRCACHESIZE
diff --git a/mbbsd/board.c b/mbbsd/board.c
index 9821edc5..3a47b0ed 100644
--- a/mbbsd/board.c
+++ b/mbbsd/board.c
@@ -543,6 +543,14 @@ load_boards(char *key)
byMALLOC = 0;
needREALLOC = (get_data_number(fav) != brdnum);
}
+#if HOTBOARDCACHE
+ else if( class_bid == -1 ){
+ nbrd = (boardstat_t *)malloc(sizeof(boardstat_t) * SHM->nHOTs);
+ for( i = 0 ; i < SHM->nHOTs ; ++i )
+ addnewbrdstat(SHM->HBcache[i] - SHM->bcache,
+ Ben_Perm(SHM->HBcache[i]));
+ }
+#endif
else { // general case
nbrd = (boardstat_t *) MALLOC(sizeof(boardstat_t) * numboards);
for (i = 0; i < numboards; i++) {
@@ -550,10 +558,13 @@ load_boards(char *key)
continue;
n = (int)(bptr - bcache);
if (!bptr->brdname[0] ||
- (bptr->brdattr & BRD_GROUPBOARD) ||
- !((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) ||
- (key[0] && !strcasestr(bptr->title, key)) ||
- (class_bid == -1 && bptr->nuser < 5))
+ (bptr->brdattr & BRD_GROUPBOARD) ||
+ !((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) ||
+ (key[0] && !strcasestr(bptr->title, key))
+#ifndef HOTBOARDCACHE
+ || (class_bid == -1 && bptr->nuser < 5)
+#endif
+ )
continue;
addnewbrdstat(n, state);
}
@@ -564,9 +575,10 @@ load_boards(char *key)
#endif
needREALLOC = 1;
}
+#ifndef HOTBOARDCACHE
if (class_bid == -1)
qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardfriends);
-
+#endif
} else { /* load boards of a subclass */
int childcount = bptr->childcount;
nbrd = (boardstat_t *) malloc(childcount * sizeof(boardstat_t));
diff --git a/sample/pttbbs.conf b/sample/pttbbs.conf
index 2d50c647..f9766815 100644
--- a/sample/pttbbs.conf
+++ b/sample/pttbbs.conf
@@ -142,6 +142,11 @@
則可透過 NO_SYSOP_ACCOUNT 關閉該帳號, 以避免安全問題發生. */
//#define NO_SYSOP_ACCOUNT
+/* 若定義, 則熱門看板列表會改用 shmctl utmpsortd 來計算, 而不是每
+ 個使用者自己算. 在站上會同時有很多人同時跑去看熱門看板的時候用.
+ 若站上並不會一瞬間很多人跑去看熱門看板, 會得到反效果. */
+//#define HOTBOARDCACHE 128
+
/* 前進站畫面 */
#define INSCREEN \
"前進站畫面 (請至 pttbbs.conf 修改您的前進站畫面)"
diff --git a/util/shmctl.c b/util/shmctl.c
index 001fd4eb..8b30c758 100644
--- a/util/shmctl.c
+++ b/util/shmctl.c
@@ -210,6 +210,8 @@ inline void utmpsort(int sortall)
userinfo_t *uentp;
int count, i, ns;
short nusers[MAX_BOARD];
+ boardheader_t *HBcache[HOTBOARDCACHE];
+
SHM->UTMPbusystate = 1;
#ifdef OUTTA_TIMER
@@ -260,9 +262,35 @@ inline void utmpsort(int sortall)
0 < uentp->brc_id && uentp->brc_id < MAX_BOARD)
++nusers[uentp->brc_id - 1];
}
- for (i = 0; i < SHM->Bnumber; ++i)
- if (SHM->bcache[i].brdname[0] != 0)
- SHM->bcache[i].nuser = nusers[i];
+ {
+#if HOTBOARDCACHE
+ int k, r, last = 0, top = 0;
+#endif
+ for (i = 0; i < SHM->Bnumber; ++i)
+ if (SHM->bcache[i].brdname[0] != 0){
+ SHM->bcache[i].nuser = nusers[i];
+#if HOTBOARDCACHE
+ if( nusers[i] > 8 &&
+ (top < HOTBOARDCACHE || nusers[i] > last) &&
+ IS_BOARD(&SHM->bcache[i]) &&
+ IS_OPENBRD(&SHM->bcache[i]) ){
+ for( k = top - 1 ; k >= 0 ; --k )
+ if( nusers[i] < HBcache[k]->nuser )
+ break;
+ if( top < HOTBOARDCACHE )
+ ++top;
+ for( r = top - 1 ; r > (k + 1) ; --r )
+ HBcache[r] = HBcache[r - 1];
+ HBcache[k + 1] = &SHM->bcache[i];
+ last = nusers[(HBcache[top - 1] - SHM->bcache)];
+ }
+#endif
+ }
+#if HOTBOARDCACHE
+ memcpy(SHM->HBcache, HBcache, sizeof(HBcache));
+ SHM->nHOTs = top;
+#endif
+ }
}
SHM->currsorted = ns;