/[LeafOK_CVS]/lbbs/src/section_list.c
ViewVC logotype

Diff of /lbbs/src/section_list.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.26 by sysadm, Tue May 27 00:54:01 2025 UTC Revision 1.32 by sysadm, Tue Jun 17 13:18:55 2025 UTC
# Line 14  Line 14 
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
 #define _GNU_SOURCE  
   
17  #include "section_list.h"  #include "section_list.h"
18  #include "log.h"  #include "log.h"
19  #include "trie_dict.h"  #include "trie_dict.h"
# Line 48  union semun Line 46  union semun
46  #define ARTICLE_BLOCK_SHM_COUNT_LIMIT 200 // limited by length (8-bit) of proj_id in ftok(path, proj_id)  #define ARTICLE_BLOCK_SHM_COUNT_LIMIT 200 // limited by length (8-bit) of proj_id in ftok(path, proj_id)
47  #define ARTICLE_BLOCK_PER_POOL (ARTICLE_BLOCK_PER_SHM * ARTICLE_BLOCK_SHM_COUNT_LIMIT)  #define ARTICLE_BLOCK_PER_POOL (ARTICLE_BLOCK_PER_SHM * ARTICLE_BLOCK_SHM_COUNT_LIMIT)
48    
49  #define CALCULATE_PAGE_THRESHOLD 100 // Adjust to tune performance of move topic  #define CALCULATE_PAGE_THRESHOLD 100 // Adjust to tune performance of moving topic between sections
50    
51  #define SID_STR_LEN 5 // 32-bit + NULL  #define SID_STR_LEN 5 // 32-bit + NULL
52    
# Line 108  int article_block_init(const char *filen Line 106  int article_block_init(const char *filen
106                  return -1;                  return -1;
107          }          }
108    
109          if (block_count > ARTICLE_BLOCK_PER_POOL)          if (block_count <= 0 || block_count > ARTICLE_BLOCK_PER_POOL)
110          {          {
111                  log_error("article_block_count exceed limit %d\n", ARTICLE_BLOCK_PER_POOL);                  log_error("article_block_count exceed limit %d\n", ARTICLE_BLOCK_PER_POOL);
112                  return -2;                  return -2;
# Line 399  ARTICLE *article_block_find_by_aid(int32 Line 397  ARTICLE *article_block_find_by_aid(int32
397                  }                  }
398          }          }
399    
400          return (p_block->articles + left);          if (aid != p_block->articles[left].aid) // not found
401            {
402                    return NULL;
403            }
404    
405            return (p_block->articles + left); // found
406  }  }
407    
408  ARTICLE *article_block_find_by_index(int index)  ARTICLE *article_block_find_by_index(int index)
# Line 605  inline static void sid_to_str(int32_t si Line 608  inline static void sid_to_str(int32_t si
608          p_sid_str[i] = '\0';          p_sid_str[i] = '\0';
609  }  }
610    
611  SECTION_LIST *section_list_create(int32_t sid, const char *sname, const char *stitle, const char *master_name)  SECTION_LIST *section_list_create(int32_t sid, const char *sname, const char *stitle, const char *master_list)
612  {  {
613          SECTION_LIST *p_section;          SECTION_LIST *p_section;
614          char sid_str[SID_STR_LEN];          char sid_str[SID_STR_LEN];
# Line 628  SECTION_LIST *section_list_create(int32_ Line 631  SECTION_LIST *section_list_create(int32_
631    
632          p_section->sid = sid;          p_section->sid = sid;
633    
634          strncpy(p_section->sname, sname, sizeof(p_section->sname - 1));          strncpy(p_section->sname, sname, sizeof(p_section->sname) - 1);
635          p_section->sname[sizeof(p_section->sname - 1)] = '\0';          p_section->sname[sizeof(p_section->sname) - 1] = '\0';
636    
637          strncpy(p_section->stitle, stitle, sizeof(p_section->stitle - 1));          strncpy(p_section->stitle, stitle, sizeof(p_section->stitle) - 1);
638          p_section->stitle[sizeof(p_section->stitle - 1)] = '\0';          p_section->stitle[sizeof(p_section->stitle) - 1] = '\0';
639    
640          strncpy(p_section->master_name, master_name, sizeof(p_section->master_name - 1));          strncpy(p_section->master_list, master_list, sizeof(p_section->master_list) - 1);
641          p_section->master_name[sizeof(p_section->master_name - 1)] = '\0';          p_section->master_list[sizeof(p_section->master_list) - 1] = '\0';
642    
643          if (trie_dict_set(p_section_list_pool->p_trie_dict_section_by_name, sname, p_section_list_pool->section_count) != 1)          if (trie_dict_set(p_section_list_pool->p_trie_dict_section_by_name, sname, p_section_list_pool->section_count) != 1)
644          {          {
# Line 1138  int32_t article_block_last_aid(void) Line 1141  int32_t article_block_last_aid(void)
1141          return last_aid;          return last_aid;
1142  }  }
1143    
1144    int article_block_article_count(void)
1145    {
1146            int ret;
1147    
1148            if (p_article_block_pool == NULL || p_article_block_pool->block_count <= 0)
1149            {
1150                    return -1;
1151            }
1152    
1153            ret = (p_article_block_pool->block_count - 1) * ARTICLE_PER_BLOCK +
1154                      p_article_block_pool->p_block[p_article_block_pool->block_count - 1]->article_count;
1155    
1156            return ret;
1157    }
1158    
1159  int article_count_of_topic(int32_t aid)  int article_count_of_topic(int32_t aid)
1160  {  {
1161          ARTICLE *p_article;          ARTICLE *p_article;
# Line 1178  int section_list_move_topic(SECTION_LIST Line 1196  int section_list_move_topic(SECTION_LIST
1196          int32_t first_inserted_aid_dest;          int32_t first_inserted_aid_dest;
1197          int move_counter;          int move_counter;
1198    
1199          if (p_section_dest == NULL)          if (p_section_src == NULL || p_section_dest == NULL)
1200          {          {
1201                  log_error("section_list_move_topic() NULL pointer error\n");                  log_error("section_list_move_topic() NULL pointer error\n");
1202                  return -1;                  return -1;
1203          }          }
1204    
1205            if (p_section_src->sid == p_section_dest->sid)
1206            {
1207                    log_error("section_list_move_topic() src and dest section are the same\n");
1208                    return -1;
1209            }
1210    
1211          if ((p_article = article_block_find_by_aid(aid)) == NULL)          if ((p_article = article_block_find_by_aid(aid)) == NULL)
1212          {          {
1213                  log_error("section_list_move_topic() error: article %d not found in block\n", aid);                  log_error("article_block_find_by_aid(aid = %d) error: article not found\n", aid);
1214                  return -2;                  return -2;
1215          }          }
1216    
# Line 1227  int section_list_move_topic(SECTION_LIST Line 1251  int section_list_move_topic(SECTION_LIST
1251          {          {
1252                  if (p_section_src->sid != p_article->sid)                  if (p_section_src->sid != p_article->sid)
1253                  {                  {
1254                          log_error("section_list_move_topic() error: src section sid %d != article %d sid %d\n",                          log_error("section_list_move_topic() warning: src section sid %d != article %d sid %d\n",
1255                                            p_section_src->sid, p_article->aid, p_article->sid);                                            p_section_src->sid, p_article->aid, p_article->sid);
1256                          return -2;                          p_article = p_article->p_topic_next;
1257                            continue;
1258                  }                  }
1259    
1260                  // Remove from bi-directional article list of src section                  // Remove from bi-directional article list of src section
# Line 1255  int section_list_move_topic(SECTION_LIST Line 1280  int section_list_move_topic(SECTION_LIST
1280    
1281                  if (section_list_find_article_with_offset(p_section_dest, p_article->aid, &page, &offset, &p_next) != NULL)                  if (section_list_find_article_with_offset(p_section_dest, p_article->aid, &page, &offset, &p_next) != NULL)
1282                  {                  {
1283                          log_error("section_list_move_topic() error: article %d already in section %d\n", p_article->aid, p_section_dest->sid);                          log_error("section_list_move_topic() warning: article %d already in section %d\n", p_article->aid, p_section_dest->sid);
1284                          return -4;                          p_article = p_article->p_topic_next;
1285                            continue;
1286                  }                  }
1287    
1288                  // Insert into bi-directional article list of dest section                  // Insert into bi-directional article list of dest section
# Line 1334  int section_list_move_topic(SECTION_LIST Line 1360  int section_list_move_topic(SECTION_LIST
1360    
1361          if (p_section_dest->article_count - dest_article_count_old != move_article_count)          if (p_section_dest->article_count - dest_article_count_old != move_article_count)
1362          {          {
1363                  log_error("section_list_move_topic() error: count of moved articles %d != %d\n",                  log_error("section_list_move_topic() warning: count of moved articles %d != %d\n",
1364                                    p_section_dest->article_count - dest_article_count_old, move_article_count);                                    p_section_dest->article_count - dest_article_count_old, move_article_count);
1365          }          }
1366    


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1