| 158 |
return ret; |
return ret; |
| 159 |
} |
} |
| 160 |
|
|
| 161 |
int append_articles_from_db(int32_t start_aid, int global_lock) |
int append_articles_from_db(int32_t start_aid, int global_lock, int article_count_limit) |
| 162 |
{ |
{ |
| 163 |
MYSQL *db; |
MYSQL *db; |
| 164 |
MYSQL_RES *rs; |
MYSQL_RES *rs; |
| 168 |
ARTICLE *p_topic; |
ARTICLE *p_topic; |
| 169 |
SECTION_LIST *p_section = NULL; |
SECTION_LIST *p_section = NULL; |
| 170 |
int32_t last_sid = 0; |
int32_t last_sid = 0; |
| 171 |
|
int article_count = 0; |
| 172 |
int ret = 0; |
int ret = 0; |
| 173 |
int i; |
int i; |
| 174 |
|
|
| 182 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 183 |
"SELECT AID, TID, SID, CID, UID, visible, excerption, ontop, `lock`, " |
"SELECT AID, TID, SID, CID, UID, visible, excerption, ontop, `lock`, " |
| 184 |
"transship, username, nickname, title, UNIX_TIMESTAMP(sub_dt) AS sub_dt " |
"transship, username, nickname, title, UNIX_TIMESTAMP(sub_dt) AS sub_dt " |
| 185 |
"FROM bbs WHERE AID >= %d ORDER BY AID", |
"FROM bbs WHERE AID >= %d ORDER BY AID LIMIT %d", |
| 186 |
start_aid); |
start_aid, article_count_limit); |
| 187 |
|
|
| 188 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 189 |
{ |
{ |
| 190 |
log_error("Query article list error: %s\n", mysql_error(db)); |
log_error("Query article list error: %s\n", mysql_error(db)); |
| 191 |
return -3; |
return -3; |
| 192 |
} |
} |
| 193 |
if ((rs = mysql_use_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 194 |
{ |
{ |
| 195 |
log_error("Get article list data failed\n"); |
log_error("Get article list data failed\n"); |
| 196 |
return -3; |
return -3; |
| 282 |
ret = -3; |
ret = -3; |
| 283 |
break; |
break; |
| 284 |
} |
} |
| 285 |
|
|
| 286 |
|
article_count++; |
| 287 |
|
|
| 288 |
|
// TODO: generate content cache |
| 289 |
} |
} |
| 290 |
|
|
| 291 |
// release lock of last section |
// release lock of last section |
| 311 |
|
|
| 312 |
mysql_close(db); |
mysql_close(db); |
| 313 |
|
|
| 314 |
return ret; |
return (ret < 0 ? ret : article_count); |
| 315 |
} |
} |
| 316 |
|
|
| 317 |
int set_last_article_op_log_from_db(void) |
int set_last_article_op_log_from_db(void) |
| 354 |
return last_article_op_log_mid; |
return last_article_op_log_mid; |
| 355 |
} |
} |
| 356 |
|
|
| 357 |
int apply_article_op_log_from_db(void) |
int apply_article_op_log_from_db(int op_count_limit) |
| 358 |
{ |
{ |
| 359 |
MYSQL *db; |
MYSQL *db; |
| 360 |
MYSQL_RES *rs, *rs2; |
MYSQL_RES *rs, *rs2; |
| 365 |
SECTION_LIST *p_section_dest; |
SECTION_LIST *p_section_dest; |
| 366 |
int32_t last_sid = 0; |
int32_t last_sid = 0; |
| 367 |
int32_t sid_dest; |
int32_t sid_dest; |
| 368 |
|
int op_count = 0; |
| 369 |
int ret = 0; |
int ret = 0; |
| 370 |
|
|
| 371 |
db = db_open(); |
db = db_open(); |
| 377 |
|
|
| 378 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 379 |
"SELECT MID, AID, type FROM bbs_article_op " |
"SELECT MID, AID, type FROM bbs_article_op " |
| 380 |
"WHERE MID > %d AND type NOT IN ('A', 'M') ORDER BY MID", |
"WHERE MID > %d AND type NOT IN ('A') " |
| 381 |
last_article_op_log_mid); |
"ORDER BY MID LIMIT %d", |
| 382 |
|
last_article_op_log_mid, op_count_limit); |
| 383 |
|
|
| 384 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 385 |
{ |
{ |
| 458 |
p_article->lock = 0; |
p_article->lock = 0; |
| 459 |
break; |
break; |
| 460 |
case 'M': // Modify article |
case 'M': // Modify article |
| 461 |
log_error("Operation type=M should not be found\n"); |
snprintf(sql, sizeof(sql), |
| 462 |
|
"SELECT CID FROM bbs WHERE AID = %d", |
| 463 |
|
p_article->aid); |
| 464 |
|
|
| 465 |
|
if (mysql_query(db, sql) != 0) |
| 466 |
|
{ |
| 467 |
|
log_error("Query article error: %s\n", mysql_error(db)); |
| 468 |
|
ret = -3; |
| 469 |
|
break; |
| 470 |
|
} |
| 471 |
|
if ((rs2 = mysql_store_result(db)) == NULL) |
| 472 |
|
{ |
| 473 |
|
log_error("Get article data failed\n"); |
| 474 |
|
ret = -3; |
| 475 |
|
break; |
| 476 |
|
} |
| 477 |
|
if ((row2 = mysql_fetch_row(rs2))) |
| 478 |
|
{ |
| 479 |
|
p_article->cid = atoi(row2[0]); |
| 480 |
|
} |
| 481 |
|
else |
| 482 |
|
{ |
| 483 |
|
p_article->cid = 0; |
| 484 |
|
ret = -4; |
| 485 |
|
} |
| 486 |
|
mysql_free_result(rs2); |
| 487 |
|
|
| 488 |
|
if (p_article->cid > 0) |
| 489 |
|
{ |
| 490 |
|
// TODO: generate content cache |
| 491 |
|
} |
| 492 |
|
|
| 493 |
break; |
break; |
| 494 |
case 'T': // Move article |
case 'T': // Move article |
| 495 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 574 |
|
|
| 575 |
// Update MID with last successfully proceeded article_op_log |
// Update MID with last successfully proceeded article_op_log |
| 576 |
last_article_op_log_mid = atoi(row[0]); |
last_article_op_log_mid = atoi(row[0]); |
| 577 |
|
|
| 578 |
|
op_count++; |
| 579 |
} |
} |
| 580 |
|
|
| 581 |
// release lock of last section |
// release lock of last section |
| 591 |
|
|
| 592 |
mysql_close(db); |
mysql_close(db); |
| 593 |
|
|
| 594 |
return ret; |
return (ret < 0 ? ret : op_count); |
| 595 |
} |
} |
| 596 |
|
|
| 597 |
int section_list_loader_launch(void) |
int section_list_loader_launch(void) |
| 652 |
} |
} |
| 653 |
|
|
| 654 |
// Load section articles |
// Load section articles |
|
last_aid = article_block_last_aid(); |
|
| 655 |
article_count = article_block_article_count(); |
article_count = article_block_article_count(); |
| 656 |
|
|
| 657 |
if ((ret = append_articles_from_db(last_aid + 1, 0)) < 0) |
do |
| 658 |
{ |
{ |
| 659 |
log_error("append_articles_from_db(%d, 0) error\n", last_aid + 1); |
last_aid = article_block_last_aid(); |
| 660 |
|
|
| 661 |
if (ret == ERR_UNKNOWN_SECTION) |
if ((ret = append_articles_from_db(last_aid + 1, 0, LOAD_ARTICLE_COUNT_LIMIT)) < 0) |
| 662 |
{ |
{ |
| 663 |
SYS_section_list_reload = 1; // Force reload section_list |
log_error("append_articles_from_db(%d, 0, %d) error\n", last_aid + 1, LOAD_ARTICLE_COUNT_LIMIT); |
| 664 |
|
|
| 665 |
|
if (ret == ERR_UNKNOWN_SECTION) |
| 666 |
|
{ |
| 667 |
|
SYS_section_list_reload = 1; // Force reload section_list |
| 668 |
|
} |
| 669 |
} |
} |
| 670 |
} |
} while (ret == LOAD_ARTICLE_COUNT_LIMIT); |
| 671 |
|
|
| 672 |
load_count = article_block_article_count() - article_count; |
load_count = article_block_article_count() - article_count; |
|
|
|
| 673 |
if (load_count > 0) |
if (load_count > 0) |
| 674 |
{ |
{ |
| 675 |
log_std("Incrementally load %d articles, last_aid = %d\n", load_count, article_block_last_aid()); |
log_std("Incrementally load %d articles, last_aid = %d\n", load_count, article_block_last_aid()); |
| 683 |
// Load article_op log |
// Load article_op log |
| 684 |
last_mid = last_article_op_log_mid; |
last_mid = last_article_op_log_mid; |
| 685 |
|
|
| 686 |
if ((ret = apply_article_op_log_from_db()) < 0) |
do |
| 687 |
{ |
{ |
| 688 |
log_error("apply_article_op_log_from_db() error\n"); |
if ((ret = apply_article_op_log_from_db(LOAD_ARTICLE_COUNT_LIMIT)) < 0) |
|
|
|
|
if (ret == ERR_UNKNOWN_SECTION) |
|
| 689 |
{ |
{ |
| 690 |
SYS_section_list_reload = 1; // Force reload section_list |
log_error("apply_article_op_log_from_db() error\n"); |
| 691 |
|
|
| 692 |
|
if (ret == ERR_UNKNOWN_SECTION) |
| 693 |
|
{ |
| 694 |
|
SYS_section_list_reload = 1; // Force reload section_list |
| 695 |
|
} |
| 696 |
} |
} |
| 697 |
} |
} while (ret == LOAD_ARTICLE_COUNT_LIMIT); |
| 698 |
|
|
| 699 |
if (last_article_op_log_mid > last_mid) |
if (last_article_op_log_mid > last_mid) |
| 700 |
{ |
{ |
| 765 |
return -2; |
return -2; |
| 766 |
} |
} |
| 767 |
|
|
| 768 |
if (page_id < 0 || page_id >= p_section->page_count) |
if (p_section->visible_article_count == 0) |
| 769 |
|
{ |
| 770 |
|
*p_article_count = 0; |
| 771 |
|
} |
| 772 |
|
else if (page_id < 0 || page_id >= p_section->page_count) |
| 773 |
{ |
{ |
| 774 |
log_error("Invalid page_id=%d, not in range [0, %d)\n", page_id, p_section->page_count); |
log_error("Invalid page_id=%d, not in range [0, %d)\n", page_id, p_section->page_count); |
| 775 |
ret = -3; |
ret = -3; |