Support for uncached data loading

So you don't have to restart the server, you can add "cache_data": false option to config.json to not cache data.
Documented in CONFIG.md
I added a require_module function that either does or does not cache the data based on this configuration option.

Signed-off-by: deadvey <deadvey@deadvey.com>
This commit is contained in:
2025-09-24 20:37:35 +01:00
parent 3f173fc2e3
commit 35e6b94ba1
4 changed files with 23 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const func = require('./functions.js')
const config = require("../config.json")
const fs = require("fs")
@@ -8,14 +9,14 @@ export function getdata(data, index=-1) {
if (config["data_storage"] == "json") {
if (data == "posts" || data == 'users' || data == 'comments') {
let result = require(`../data/${data}.json`)
let result = func.require_module(`../data/${data}.json`)
if (index != -1) {
return result[index]
}
return result
}
else if (data == "hitcount") {
let result = require('../data/data.json') // This file is actually called data.json
let result = func.require_module('../data/data.json') // This file is actually called data.json
return result["hitcount"]
}
else {