| 1 |
/*************************************************************************** |
/* SPDX-License-Identifier: GPL-3.0-or-later */ |
| 2 |
user_list.c - description |
/* |
| 3 |
------------------- |
* user_stat |
| 4 |
Copyright : (C) 2004-2025 by Leaflet |
* - data model and basic operations of user related statistics |
| 5 |
Email : leaflet@leafok.com |
* |
| 6 |
***************************************************************************/ |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
| 7 |
|
*/ |
| 8 |
/*************************************************************************** |
|
| 9 |
* * |
#ifdef HAVE_CONFIG_H |
| 10 |
* This program is free software; you can redistribute it and/or modify * |
#include "config.h" |
| 11 |
* it under the terms of the GNU General Public License as published by * |
#endif |
|
* the Free Software Foundation; either version 3 of the License, or * |
|
|
* (at your option) any later version. * |
|
|
* * |
|
|
***************************************************************************/ |
|
| 12 |
|
|
| 13 |
#include "log.h" |
#include "log.h" |
| 14 |
#include "section_list.h" |
#include "section_list.h" |
| 19 |
{ |
{ |
| 20 |
if (p_map == NULL) |
if (p_map == NULL) |
| 21 |
{ |
{ |
| 22 |
log_error("NULL pointer error\n"); |
log_error("NULL pointer error"); |
| 23 |
return -1; |
return -1; |
| 24 |
} |
} |
| 25 |
|
|
| 40 |
|
|
| 41 |
if (p_map == NULL) |
if (p_map == NULL) |
| 42 |
{ |
{ |
| 43 |
log_error("NULL pointer error\n"); |
log_error("NULL pointer error"); |
| 44 |
return -1; |
return -1; |
| 45 |
} |
} |
| 46 |
|
|
| 47 |
// Load uid_list |
// Load uid_list |
| 48 |
if (get_user_id_list(uid_list, &user_cnt, p_map->last_uid + 1) < 0) |
if (get_user_id_list(uid_list, &user_cnt, p_map->last_uid + 1) < 0) |
| 49 |
{ |
{ |
| 50 |
log_error("get_user_id_list(%d, 0) error\n", user_cnt); |
log_error("get_user_id_list(%d, 0) error", user_cnt); |
| 51 |
return -2; |
return -2; |
| 52 |
} |
} |
| 53 |
|
|
| 67 |
p_article = article_block_find_by_index(i); |
p_article = article_block_find_by_index(i); |
| 68 |
if (p_article == NULL) |
if (p_article == NULL) |
| 69 |
{ |
{ |
| 70 |
log_error("article_block_find_by_index(index=%d) error\n", i); |
log_error("article_block_find_by_index(index=%d) error", i); |
| 71 |
break; |
break; |
| 72 |
} |
} |
| 73 |
|
|
| 74 |
|
if (p_article->visible == 0) |
| 75 |
|
{ |
| 76 |
|
continue; |
| 77 |
|
} |
| 78 |
|
|
| 79 |
if (p_article->uid > p_map->last_uid) |
if (p_article->uid > p_map->last_uid) |
| 80 |
{ |
{ |
| 81 |
#ifdef _DEBUG |
log_debug("uid=%d of article(aid=%d) is greater than last_uid=%d", |
|
log_error("uid=%d of article(aid=%d) is greater than last_uid=%d, waiting for next user list update\n", |
|
| 82 |
p_article->uid, p_article->aid, p_map->last_uid); |
p_article->uid, p_article->aid, p_map->last_uid); |
| 83 |
#endif |
continue; |
|
break; |
|
| 84 |
} |
} |
| 85 |
|
|
| 86 |
if (user_stat_article_cnt_inc(p_map, p_article->uid, 1) < 0) |
if (user_stat_article_cnt_inc(p_map, p_article->uid, 1) < 0) |
| 87 |
{ |
{ |
| 88 |
log_error("user_stat_article_cnt_inc(uid=%d, 1) error\n", p_article->uid); |
log_error("user_stat_article_cnt_inc(uid=%d, 1) error", p_article->uid); |
| 89 |
break; |
break; |
| 90 |
} |
} |
| 91 |
} |
} |
| 103 |
|
|
| 104 |
if (p_map == NULL) |
if (p_map == NULL) |
| 105 |
{ |
{ |
| 106 |
log_error("NULL pointer error\n"); |
log_error("NULL pointer error"); |
| 107 |
return -1; |
return -1; |
| 108 |
} |
} |
| 109 |
|
|
| 115 |
mid = (left + right) / 2; |
mid = (left + right) / 2; |
| 116 |
if (uid < p_map->stat_list[mid].uid) |
if (uid < p_map->stat_list[mid].uid) |
| 117 |
{ |
{ |
| 118 |
right = mid; |
right = mid - 1; |
| 119 |
} |
} |
| 120 |
else if (uid > p_map->stat_list[mid].uid) |
else if (uid > p_map->stat_list[mid].uid) |
| 121 |
{ |
{ |
| 145 |
|
|
| 146 |
if (p_map == NULL) |
if (p_map == NULL) |
| 147 |
{ |
{ |
| 148 |
log_error("NULL pointer error\n"); |
log_error("NULL pointer error"); |
| 149 |
return -1; |
return -1; |
| 150 |
} |
} |
| 151 |
|
|
| 157 |
mid = (left + right) / 2; |
mid = (left + right) / 2; |
| 158 |
if (uid < p_map->stat_list[mid].uid) |
if (uid < p_map->stat_list[mid].uid) |
| 159 |
{ |
{ |
| 160 |
right = mid; |
right = mid - 1; |
| 161 |
} |
} |
| 162 |
else if (uid > p_map->stat_list[mid].uid) |
else if (uid > p_map->stat_list[mid].uid) |
| 163 |
{ |
{ |