| 17 |
#include "log.h" |
#include "log.h" |
| 18 |
#include "section_list.h" |
#include "section_list.h" |
| 19 |
#include "trie_dict.h" |
#include "trie_dict.h" |
| 20 |
|
#include "user_list.h" |
| 21 |
#include <errno.h> |
#include <errno.h> |
| 22 |
#include <signal.h> |
#include <signal.h> |
| 23 |
#include <stdio.h> |
#include <stdio.h> |
| 650 |
return p_section; |
return p_section; |
| 651 |
} |
} |
| 652 |
|
|
| 653 |
|
int section_list_update(SECTION_LIST *p_section, const char *sname, const char *stitle, const char *master_list) |
| 654 |
|
{ |
| 655 |
|
int64_t index; |
| 656 |
|
|
| 657 |
|
if (p_section == NULL || sname == NULL || stitle == NULL || master_list == NULL) |
| 658 |
|
{ |
| 659 |
|
log_error("NULL pointer error\n"); |
| 660 |
|
return -1; |
| 661 |
|
} |
| 662 |
|
|
| 663 |
|
index = get_section_index(p_section); |
| 664 |
|
|
| 665 |
|
strncpy(p_section->sname, sname, sizeof(p_section->sname) - 1); |
| 666 |
|
p_section->sname[sizeof(p_section->sname) - 1] = '\0'; |
| 667 |
|
|
| 668 |
|
strncpy(p_section->stitle, stitle, sizeof(p_section->stitle) - 1); |
| 669 |
|
p_section->stitle[sizeof(p_section->stitle) - 1] = '\0'; |
| 670 |
|
|
| 671 |
|
strncpy(p_section->master_list, master_list, sizeof(p_section->master_list) - 1); |
| 672 |
|
p_section->master_list[sizeof(p_section->master_list) - 1] = '\0'; |
| 673 |
|
|
| 674 |
|
if (trie_dict_set(p_section_list_pool->p_trie_dict_section_by_name, sname, index) < 0) |
| 675 |
|
{ |
| 676 |
|
log_error("trie_dict_set(section, %s, %d) error\n", sname, index); |
| 677 |
|
return -2; |
| 678 |
|
} |
| 679 |
|
|
| 680 |
|
return 0; |
| 681 |
|
} |
| 682 |
|
|
| 683 |
void section_list_reset_articles(SECTION_LIST *p_section) |
void section_list_reset_articles(SECTION_LIST *p_section) |
| 684 |
{ |
{ |
| 685 |
p_section->article_count = 0; |
p_section->article_count = 0; |
| 926 |
{ |
{ |
| 927 |
p_section->visible_article_count--; |
p_section->visible_article_count--; |
| 928 |
|
|
| 929 |
|
if (user_article_cnt_inc(p_article->uid, -1) < 0) |
| 930 |
|
{ |
| 931 |
|
log_error("user_article_cnt_inc(uid=%d, -1) error\n", p_article->uid); |
| 932 |
|
} |
| 933 |
|
|
| 934 |
if (p_article->tid == 0) |
if (p_article->tid == 0) |
| 935 |
{ |
{ |
| 936 |
p_section->visible_topic_count--; |
p_section->visible_topic_count--; |
| 949 |
p_reply->visible = 0; |
p_reply->visible = 0; |
| 950 |
p_section->visible_article_count--; |
p_section->visible_article_count--; |
| 951 |
affected_count++; |
affected_count++; |
| 952 |
|
|
| 953 |
|
if (user_article_cnt_inc(p_reply->uid, -1) < 0) |
| 954 |
|
{ |
| 955 |
|
log_error("user_article_cnt_inc(uid=%d, -1) error\n", p_reply->uid); |
| 956 |
|
} |
| 957 |
} |
} |
| 958 |
} |
} |
| 959 |
} |
} |
| 966 |
{ |
{ |
| 967 |
p_section->visible_topic_count++; |
p_section->visible_topic_count++; |
| 968 |
} |
} |
| 969 |
|
|
| 970 |
|
if (user_article_cnt_inc(p_article->uid, 1) < 0) |
| 971 |
|
{ |
| 972 |
|
log_error("user_article_cnt_inc(uid=%d, 1) error\n", p_article->uid); |
| 973 |
|
} |
| 974 |
} |
} |
| 975 |
|
|
| 976 |
p_article->visible = visible; |
p_article->visible = visible; |
| 1731 |
timer++; |
timer++; |
| 1732 |
if (timer % SECTION_TRY_LOCK_TIMES == 0) |
if (timer % SECTION_TRY_LOCK_TIMES == 0) |
| 1733 |
{ |
{ |
| 1734 |
log_error("section_list_try_rd_lock() tried %d times on section %d\n", sid, timer); |
log_error("section_list_try_rd_lock() tried %d times on section %d\n", timer, sid); |
| 1735 |
} |
} |
| 1736 |
} |
} |
| 1737 |
else // failed |
else // failed |
| 1762 |
timer++; |
timer++; |
| 1763 |
if (timer % SECTION_TRY_LOCK_TIMES == 0) |
if (timer % SECTION_TRY_LOCK_TIMES == 0) |
| 1764 |
{ |
{ |
| 1765 |
log_error("section_list_try_rw_lock() tried %d times on section %d\n", sid, timer); |
log_error("section_list_try_rw_lock() tried %d times on section %d\n", timer, sid); |
| 1766 |
} |
} |
| 1767 |
} |
} |
| 1768 |
else // failed |
else // failed |