/[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.3 by sysadm, Wed May 21 06:17:52 2025 UTC Revision 1.6 by sysadm, Wed May 21 12:43:04 2025 UTC
# Line 16  Line 16 
16    
17  #include "section_list.h"  #include "section_list.h"
18  #include "log.h"  #include "log.h"
 #include "io.h"  
19  #include "trie_dict.h"  #include "trie_dict.h"
20  #include <stdio.h>  #include <stdio.h>
21  #include <string.h>  #include <string.h>
# Line 30  Line 29 
29  // ARTICLE_BLOCK_PER_SHM * ARTICLE_BLOCK_SHM_COUNT_LIMIT should be  // ARTICLE_BLOCK_PER_SHM * ARTICLE_BLOCK_SHM_COUNT_LIMIT should be
30  // no less than BBS_article_block_limit_per_section * BBS_max_section,  // no less than BBS_article_block_limit_per_section * BBS_max_section,
31  // in order to allocate enough memory for blocks  // in order to allocate enough memory for blocks
32  #define ARTICLE_BLOCK_PER_SHM 50 // sizeof(ARTICLE_BLOCK) * ARTICLE_BLOCK_PER_SHM is the size of each shm segment to allocate  #define ARTICLE_BLOCK_PER_SHM 400 // sizeof(ARTICLE_BLOCK) * ARTICLE_BLOCK_PER_SHM is the size of each shm segment to allocate
33  #define ARTICLE_BLOCK_SHM_COUNT_LIMIT 256 // limited by length (8-bit) of proj_id in ftok(path, proj_id)  #define ARTICLE_BLOCK_SHM_COUNT_LIMIT 256 // limited by length (8-bit) of proj_id in ftok(path, proj_id)
34    
35  struct article_block_shm_t  struct article_block_shm_t
# Line 252  SECTION_DATA *section_data_create(const Line 251  SECTION_DATA *section_data_create(const
251          p_section->article_count = 0;          p_section->article_count = 0;
252          p_section->delete_count = 0;          p_section->delete_count = 0;
253    
254            p_section->p_article_head = NULL;
255            p_section->p_article_tail = NULL;
256    
257          if (trie_dict_set(p_trie_dict_section_data, sname, index) != 1)          if (trie_dict_set(p_trie_dict_section_data, sname, index) != 1)
258          {          {
259                  log_error("trie_dict_set(section_data, %s, %d) error\n", sname, index);                  log_error("trie_dict_set(section_data, %s, %d) error\n", sname, index);
# Line 291  int section_data_free_block(SECTION_DATA Line 293  int section_data_free_block(SECTION_DATA
293          p_section->article_count = 0;          p_section->article_count = 0;
294          p_section->delete_count = 0;          p_section->delete_count = 0;
295    
296            p_section->p_article_head = NULL;
297            p_section->p_article_tail = NULL;
298    
299          return 0;          return 0;
300  }  }
301    
302  SECTION_DATA *section_data_find_by_name(const char *sname)  SECTION_DATA *section_data_find_section_by_name(const char *sname)
303  {  {
304          int64_t index;          int64_t index;
305    
# Line 313  SECTION_DATA *section_data_find_by_name( Line 318  SECTION_DATA *section_data_find_by_name(
318          return (p_section_data_pool + index);          return (p_section_data_pool + index);
319  }  }
320    
321  int section_data_append_article(SECTION_DATA *p_section, const ARTICLE *p_article)  int section_data_append_article(SECTION_DATA *p_section, const ARTICLE *p_article_src)
322  {  {
323          ARTICLE_BLOCK *p_block;          ARTICLE_BLOCK *p_block;
324          int32_t last_aid = 0;          int32_t last_aid = 0;
325            ARTICLE *p_article;
326          ARTICLE *p_topic_head;          ARTICLE *p_topic_head;
327          ARTICLE *p_topic_tail;          ARTICLE *p_topic_tail;
328    
329          if (p_section == NULL || p_article == NULL)          if (p_section == NULL || p_article_src == NULL)
330          {          {
331                  log_error("section_data_append_article() NULL pointer error\n");                  log_error("section_data_append_article() NULL pointer error\n");
332                  return -1;                  return -1;
# Line 357  int section_data_append_article(SECTION_ Line 363  int section_data_append_article(SECTION_
363                  else                  else
364                  {                  {
365                          p_section->p_tail_block->p_next_block = p_block;                          p_section->p_tail_block->p_next_block = p_block;
366                          last_aid = p_section->p_tail_block->articles[BBS_article_limit_per_block - 1].aid;                          last_aid = p_section->p_article_tail->aid;
367                  }                  }
368                  p_section->p_tail_block = p_block;                  p_section->p_tail_block = p_block;
369                  p_section->p_block[p_section->block_count] = p_block;                  p_section->p_block[p_section->block_count] = p_block;
# Line 366  int section_data_append_article(SECTION_ Line 372  int section_data_append_article(SECTION_
372          else          else
373          {          {
374                  p_block = p_section->p_tail_block;                  p_block = p_section->p_tail_block;
375                  last_aid = p_block->articles[p_block->article_count - 1].aid;                  last_aid = p_section->p_article_tail->aid;
376          }          }
377    
378          // AID of articles should be strictly ascending          // AID of articles should be strictly ascending
379          if (p_article->aid <= last_aid)          if (p_article_src->aid <= last_aid)
380          {          {
381                  log_error("section_data_append_article(aid=%d) error: last_aid=%d\n", p_article->aid, last_aid);                  log_error("section_data_append_article(aid=%d) error: last_aid=%d\n", p_article_src->aid, last_aid);
382                  return -3;                  return -3;
383          }          }
384    
385          if (p_block->article_count == 0)          if (p_block->article_count == 0)
386          {          {
387                  p_section->block_head_aid[p_section->block_count - 1] = p_article->aid;                  p_section->block_head_aid[p_section->block_count - 1] = p_article_src->aid;
388          }          }
389    
390          if (p_article->tid != 0)          if (p_article_src->tid != 0)
391          {          {
392                  p_topic_head = section_data_find_article_by_aid(p_section, p_article->tid);                  p_topic_head = section_data_find_article_by_aid(p_section, p_article_src->tid);
393                  if (p_topic_head == NULL)                  if (p_topic_head == NULL)
394                  {                  {
395                          log_error("search head of topic (aid=%d) error\n", p_article->tid);                          log_error("search head of topic (aid=%d) error\n", p_article_src->tid);
396                          return -4;                          return -4;
397                  }                  }
398    
399                  p_topic_tail = section_data_find_article_by_aid(p_section, p_topic_head->prior_aid);                  p_topic_tail = p_topic_head->p_topic_prior;
400                  if (p_topic_tail == NULL)                  if (p_topic_tail == NULL)
401                  {                  {
402                          log_error("search tail of topic (aid=%d) error\n", p_topic_head->prior_aid);                          log_error("tail of topic (aid=%d) is NULL\n", p_article_src->tid);
403                          return -4;                          return -4;
404                  }                  }
405          }          }
# Line 403  int section_data_append_article(SECTION_ Line 409  int section_data_append_article(SECTION_
409                  p_topic_tail = p_topic_head;                  p_topic_tail = p_topic_head;
410          }          }
411    
412            p_article = &(p_block->articles[p_block->article_count]);
413    
414          // Copy article data          // Copy article data
415          p_block->articles[p_block->article_count] = *p_article;          *p_article = *p_article_src;
416    
417          // Link appended article as tail node of topic bi-directional list;          // Link appended article as tail node of article bi-directional list
418          p_block->articles[p_block->article_count].prior_aid = p_topic_tail->aid;          if (p_section->p_article_head == NULL)
419          p_block->articles[p_block->article_count].next_aid = p_topic_head->aid;          {
420          p_topic_head->prior_aid = p_article->aid;                  p_section->p_article_head = p_article;
421          p_topic_tail->next_aid = p_article->aid;                  p_section->p_article_tail = p_article;
422            }
423            p_article->p_prior = p_section->p_article_tail;
424            p_article->p_next = p_section->p_article_head;
425            p_section->p_article_head->p_prior = p_article;
426            p_section->p_article_tail->p_next = p_article;
427            p_section->p_article_tail = p_article;
428    
429            // Link appended article as tail node of topic bi-directional list
430            p_article->p_topic_prior = p_topic_tail;
431            p_article->p_topic_next = p_topic_head;
432            p_topic_head->p_topic_prior = p_article;
433            p_topic_tail->p_topic_next = p_article;
434    
435          p_block->article_count++;          p_block->article_count++;
436          p_section->article_count++;          p_section->article_count++;


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

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