-
@无名啊,
1. 全文搜索不是事儿
2. 增量备份没必要,一般纯文本的数据不会超过3GB
3. 一天备份一次
4. 服务器程序一般不会断电
5. SSD的速度很快了,人类几乎没有延时感。同时纯文本要做memory dict cache,保存最近访问的1000个文章,快如闪电。
我之前用Python写过类似的数据库,只不过没写中心化的pipe line,多进程会出问题:
https://github.com/yingshaoxo/auto_everything/blob/dev/auto_everything/database.py#L357
其中一点代码:
“”“
if self.use_sqlite == False:
self.database_txt_file_path = self._disk.join_paths(self.database_base_folder, f"{self.database_name}.txt")
if (not self._disk.exists(self.database_txt_file_path)):
self._io.write(self.database_txt_file_path, "")
”“”
“”“
def raw_search(self, one_row_json_string_handler: Callable[[str], dict[str, Any] | None]) -> Iterator[dict[str, Any]]:
"""
one_row_json_string_handler: a_function to handle search process. If it returns None, we'll ignore it, otherwise, we'll add the return value into the result list.
```
def one_row_json_string_handler(item: str) -> dict[str, Any] | None:
return json.loads(item)
#return None
```
"""
if self.global_multiprocessing_shared_dict != None:
self._wait_until_unlock()
self.global_multiprocessing_shared_dict[self._the_key_for_the_lock_of_memory_data] = True
for row in self.global_multiprocessing_shared_dict[self._the_key_for_memory_data]:
json_string = self._json.dumps(row, sort_keys=True).strip()
result = one_row_json_string_handler(json_string)
if (result != None):
yield result
self.global_multiprocessing_shared_dict[self._the_key_for_the_lock_of_memory_data] = False
return
if self.use_sqlite:
for row in self.sql_cursor.execute(
f"SELECT * FROM {self._sql_table_name}"
):
result = one_row_json_string_handler(row[0])
if (result != None):
yield result
else:
with open(self.database_txt_file_path, "r") as file_stream:
previous_position = None
while True:
current_position = file_stream.tell()
line = file_stream.readline()
if previous_position == current_position:
# reach the end
break
previous_position = current_position
if (line.strip() == ""):
# ignore empty line
continue
if (line.startswith('#')):
# ignore deleted line
continue
result = one_row_json_string_handler(line)
if (result != None):
yield result
”“”
-
@老虎会游泳,
谢谢,改了db folder permission后,原错误确实消失了。
后来我自己建了一个新的sqlite的db文件,现在主页可以访问了:
https://gitlab.com/yingshaoxo/tiger_bbs_php5.4.45/-/blob/main/db/sqlite.sql_command?ref_type=heads
https://gitlab.com/yingshaoxo/tiger_bbs_php5.4.45/-/blob/main/db/test.db3?ref_type=heads
但无法注册用户,会报错。
新的错误:
错误代码:22
错误信息:数据库写入错误,SQL预处理失败。
错误发生在 /var/www/html/class/user.php 的第 416 行
错误追踪信息:
#0 /var/www/html/page/user/reg.php(30): user->reg('yingshaoxo', 'password', 'yingshaoxo@gmai...')
#1 /var/www/html/q.php(74): include('/var/www/html/p...')
#2 {main}
$rs = $db->prepare('SELECT `active`,`uid`,`name`,`mail`,`sid`,`sidtime`,`regtime`,`acctime`' . ($getinfo ? ',`info`' : '') . ' FROM `' . DB_A . 'user` WHERE `sid`=?');
$x_getinfo = $getinfo;
}
if (!$rs || !$rs->execute(array($sid))) throw new PDOException('数据库查询失败,SQL' . ($rs ? '执行' : '预处理') . '失败。', $rs ? 21 : 22);
$data = $rs->fetch(db::ass);
______
> 以下不是重点:
我不太懂php的程序,感觉编译器太难固定了,我之前找到一个5.7MB的x86_linux静态编译的Python3.2程序,感觉就挺好用:
https://gitlab.com/yingshaoxo/yingshaoxo_alpine_x86_system/-/blob/main/python?ref_type=heads
我感觉如果我有时间的话,都想用python重写一遍简单的wap论坛了,完全脱离docker,sql,javascript,php,就简单的自实现的http server + file read/write + html + css