| 169 |
ARTICLE *p_topic; |
ARTICLE *p_topic; |
| 170 |
SECTION_LIST *p_section = NULL; |
SECTION_LIST *p_section = NULL; |
| 171 |
int32_t last_sid = 0; |
int32_t last_sid = 0; |
| 172 |
|
char sub_ip[IP_ADDR_LEN]; |
| 173 |
int article_count = 0; |
int article_count = 0; |
| 174 |
int ret = 0; |
int ret = 0; |
| 175 |
int i; |
int i; |
| 184 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 185 |
"SELECT bbs.AID, TID, SID, bbs.CID, UID, visible, excerption, ontop, `lock`, " |
"SELECT bbs.AID, TID, SID, bbs.CID, UID, visible, excerption, ontop, `lock`, " |
| 186 |
"transship, username, nickname, title, UNIX_TIMESTAMP(sub_dt) AS sub_dt, " |
"transship, username, nickname, title, UNIX_TIMESTAMP(sub_dt) AS sub_dt, " |
| 187 |
"bbs_content.content " |
"sub_ip, bbs_content.content " |
| 188 |
"FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID " |
"FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID " |
| 189 |
"WHERE bbs.AID >= %d ORDER BY bbs.AID LIMIT %d", |
"WHERE bbs.AID >= %d ORDER BY bbs.AID LIMIT %d", |
| 190 |
start_aid, article_count_limit); |
start_aid, article_count_limit); |
| 237 |
|
|
| 238 |
article.sub_dt = atol(row[i++]); |
article.sub_dt = atol(row[i++]); |
| 239 |
|
|
| 240 |
|
strncpy(sub_ip, row[i++], sizeof(sub_ip) - 1); |
| 241 |
|
sub_ip[sizeof(sub_ip) - 1] = '\0'; |
| 242 |
|
ip_mask(sub_ip, 1, '*'); |
| 243 |
|
|
| 244 |
// release lock of last section if different from current one |
// release lock of last section if different from current one |
| 245 |
if (!global_lock && article.sid != last_sid && last_sid != 0) |
if (!global_lock && article.sid != last_sid && last_sid != 0) |
| 246 |
{ |
{ |
| 293 |
|
|
| 294 |
article_count++; |
article_count++; |
| 295 |
|
|
| 296 |
if (article_cache_generate(VAR_ARTICLE_CACHE_DIR, &article, p_section, row[i++], 0) < 0) |
if (article_cache_generate(VAR_ARTICLE_CACHE_DIR, &article, p_section, row[i++], sub_ip, 0) < 0) |
| 297 |
{ |
{ |
| 298 |
log_error("article_cache_generate(aid=%d, cid=%d) error\n", article.aid, article.cid); |
log_error("article_cache_generate(aid=%d, cid=%d) error\n", article.aid, article.cid); |
| 299 |
ret = -4; |
ret = -4; |
| 376 |
ARTICLE *p_article; |
ARTICLE *p_article; |
| 377 |
SECTION_LIST *p_section = NULL; |
SECTION_LIST *p_section = NULL; |
| 378 |
SECTION_LIST *p_section_dest; |
SECTION_LIST *p_section_dest; |
| 379 |
|
char sub_ip[IP_ADDR_LEN]; |
| 380 |
int32_t last_sid = 0; |
int32_t last_sid = 0; |
| 381 |
int32_t sid_dest; |
int32_t sid_dest; |
| 382 |
int op_count = 0; |
int op_count = 0; |
| 473 |
break; |
break; |
| 474 |
case 'M': // Modify article |
case 'M': // Modify article |
| 475 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 476 |
"SELECT bbs.CID, bbs_content.content " |
"SELECT bbs.CID, sub_ip, bbs_content.content " |
| 477 |
"FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID " |
"FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID " |
| 478 |
"WHERE bbs.AID = %d", |
"WHERE bbs.AID = %d", |
| 479 |
p_article->aid); |
p_article->aid); |
| 494 |
{ |
{ |
| 495 |
p_article->cid = atoi(row2[0]); |
p_article->cid = atoi(row2[0]); |
| 496 |
|
|
| 497 |
if (article_cache_generate(VAR_ARTICLE_CACHE_DIR, p_article, p_section, row2[1], 0) < 0) |
strncpy(sub_ip, row2[1], sizeof(sub_ip) - 1); |
| 498 |
|
sub_ip[sizeof(sub_ip) - 1] = '\0'; |
| 499 |
|
ip_mask(sub_ip, 1, '*'); |
| 500 |
|
|
| 501 |
|
if (article_cache_generate(VAR_ARTICLE_CACHE_DIR, p_article, p_section, row2[2], sub_ip, 0) < 0) |
| 502 |
{ |
{ |
| 503 |
log_error("article_cache_generate(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); |
log_error("article_cache_generate(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); |
| 504 |
ret = -4; |
ret = -4; |
| 636 |
{ |
{ |
| 637 |
SYS_child_process_count++; |
SYS_child_process_count++; |
| 638 |
section_list_loader_pid = pid; |
section_list_loader_pid = pid; |
| 639 |
log_std("Section list loader process (%d) start\n", pid); |
log_common("Section list loader process (pid = %d) start\n", pid); |
| 640 |
return 0; |
return 0; |
| 641 |
} |
} |
| 642 |
else if (pid < 0) // Error |
else if (pid < 0) // Error |
| 692 |
load_count = article_block_article_count() - article_count; |
load_count = article_block_article_count() - article_count; |
| 693 |
if (load_count > 0) |
if (load_count > 0) |
| 694 |
{ |
{ |
| 695 |
log_std("Incrementally load %d articles, last_aid = %d\n", load_count, article_block_last_aid()); |
log_common("Incrementally load %d articles, last_aid = %d\n", load_count, article_block_last_aid()); |
| 696 |
} |
} |
| 697 |
|
|
| 698 |
if (SYS_section_list_reload) |
if (SYS_section_list_reload) |
| 718 |
|
|
| 719 |
if (last_article_op_log_mid > last_mid) |
if (last_article_op_log_mid > last_mid) |
| 720 |
{ |
{ |
| 721 |
log_std("Proceeded %d article logs, last_mid = %d\n", last_article_op_log_mid - last_mid, last_article_op_log_mid); |
log_common("Proceeded %d article logs, last_mid = %d\n", last_article_op_log_mid - last_mid, last_article_op_log_mid); |
| 722 |
} |
} |
| 723 |
|
|
| 724 |
if (SYS_section_list_reload) |
if (SYS_section_list_reload) |
| 739 |
detach_article_block_shm(); |
detach_article_block_shm(); |
| 740 |
detach_trie_dict_shm(); |
detach_trie_dict_shm(); |
| 741 |
|
|
| 742 |
log_std("Section list loader process exit normally\n"); |
log_common("Section list loader process exit normally\n"); |
| 743 |
log_end(); |
log_end(); |
| 744 |
|
|
| 745 |
section_list_loader_pid = 0; |
section_list_loader_pid = 0; |
| 829 |
|
|
| 830 |
return ret; |
return ret; |
| 831 |
} |
} |
| 832 |
|
|
| 833 |
|
int locate_article_in_section(SECTION_LIST *p_section, const ARTICLE *p_article_cur, int direction, |
| 834 |
|
int *p_page_id, int *p_visible_offset, int *p_article_count) |
| 835 |
|
{ |
| 836 |
|
const ARTICLE *p_article = NULL; |
| 837 |
|
ARTICLE *p_tmp; |
| 838 |
|
int32_t aid = 0; |
| 839 |
|
int page_id; |
| 840 |
|
int offset; |
| 841 |
|
int ret = 0; |
| 842 |
|
int i; |
| 843 |
|
|
| 844 |
|
if (p_section == NULL || p_article_cur == NULL || p_page_id == NULL || p_visible_offset == NULL || p_article_count == NULL) |
| 845 |
|
{ |
| 846 |
|
log_error("locate_article_in_section() NULL pointer error\n"); |
| 847 |
|
return -1; |
| 848 |
|
} |
| 849 |
|
|
| 850 |
|
// acquire lock of section |
| 851 |
|
if ((ret = section_list_rd_lock(p_section)) < 0) |
| 852 |
|
{ |
| 853 |
|
log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid); |
| 854 |
|
return -2; |
| 855 |
|
} |
| 856 |
|
|
| 857 |
|
if (direction == 0) |
| 858 |
|
{ |
| 859 |
|
aid = p_article_cur->aid; |
| 860 |
|
} |
| 861 |
|
else if (direction == 1) |
| 862 |
|
{ |
| 863 |
|
p_article = p_article_cur; |
| 864 |
|
do |
| 865 |
|
{ |
| 866 |
|
p_article = p_article->p_topic_next; |
| 867 |
|
} while (p_article != p_article_cur && p_article->visible == 0); |
| 868 |
|
|
| 869 |
|
aid = (p_article->aid > p_article_cur->aid ? p_article->aid : 0); |
| 870 |
|
} |
| 871 |
|
else if (direction == -1) |
| 872 |
|
{ |
| 873 |
|
p_article = p_article_cur; |
| 874 |
|
do |
| 875 |
|
{ |
| 876 |
|
p_article = p_article->p_topic_prior; |
| 877 |
|
} while (p_article != p_article_cur && p_article->visible == 0); |
| 878 |
|
|
| 879 |
|
aid = (p_article->aid < p_article_cur->aid ? p_article->aid : 0); |
| 880 |
|
} |
| 881 |
|
|
| 882 |
|
p_article = NULL; |
| 883 |
|
|
| 884 |
|
if (aid > 0) |
| 885 |
|
{ |
| 886 |
|
p_article = section_list_find_article_with_offset(p_section, aid, &page_id, &offset, &p_tmp); |
| 887 |
|
if (p_article != NULL) |
| 888 |
|
{ |
| 889 |
|
*p_article_count = (page_id == p_section->page_count - 1 ? p_section->last_page_visible_article_count : BBS_article_limit_per_page); |
| 890 |
|
|
| 891 |
|
p_article = p_section->p_page_first_article[page_id]; |
| 892 |
|
for (i = 0; i < *p_article_count;) |
| 893 |
|
{ |
| 894 |
|
if (p_article->visible) |
| 895 |
|
{ |
| 896 |
|
if (p_article->aid == aid) |
| 897 |
|
{ |
| 898 |
|
*p_page_id = page_id; |
| 899 |
|
*p_visible_offset = i; |
| 900 |
|
break; |
| 901 |
|
} |
| 902 |
|
i++; |
| 903 |
|
if (i >= *p_article_count) |
| 904 |
|
{ |
| 905 |
|
log_error("Visible article (aid=%d) not found in page %d\n", aid, page_id); |
| 906 |
|
p_article = NULL; |
| 907 |
|
} |
| 908 |
|
} |
| 909 |
|
p_article = p_article->p_next; |
| 910 |
|
} |
| 911 |
|
} |
| 912 |
|
} |
| 913 |
|
|
| 914 |
|
// release lock of section |
| 915 |
|
if (section_list_rd_unlock(p_section) < 0) |
| 916 |
|
{ |
| 917 |
|
log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid); |
| 918 |
|
ret = -2; |
| 919 |
|
} |
| 920 |
|
|
| 921 |
|
return (ret < 0 ? ret : (p_article == NULL ? 0 : 1)); |
| 922 |
|
} |