out gc and download index
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
ale 2024-09-22 00:49:45 +02:00
parent 42b9e7b701
commit 6ce68b15c5
3 changed files with 32 additions and 5 deletions

View File

@ -2,6 +2,7 @@ const nodeinfo = require('activitypub-express/pub/nodeinfo')
module.exports = (app, client) => { module.exports = (app, client) => {
const constant = require('./constant'), const constant = require('./constant'),
zlib = require('zlib'),
clean = str => { clean = str => {
return str.replace(/[\/\\^$+?()`'¡¿¨!"·%&=;,\|\[\]{}]+/gmi, '') return str.replace(/[\/\\^$+?()`'¡¿¨!"·%&=;,\|\[\]{}]+/gmi, '')
} }
@ -476,7 +477,6 @@ module.exports = (app, client) => {
instancescomment = instances.map(i => ({ instancescomment = instances.map(i => ({
instance: i._source.instance, comment: i._source.blocks.find(block => block.domain === clean(req.params.instance)).comment instance: i._source.instance, comment: i._source.blocks.find(block => block.domain === clean(req.params.instance)).comment
})) }))
global.gc()
res.json({ res.json({
block_count: instances.length, block_count: instances.length,
instances: instancescomment, instances: instancescomment,
@ -486,4 +486,34 @@ module.exports = (app, client) => {
res.status(404).end() res.status(404).end()
} }
}) })
/**
* @swagger
* /api/download_index:
* get:
* summary: Retrieve all content of ElasticSearch index.
* description: Retrieve all content of ElasticSearch index.
* responses:
* 200:
* description: A file compressed with gzip.
* content:
* application/octect-stream
*/
app.use('/api/download_index', async (req, res) => {
if (req.params.instance && req.params.instance.length > 0) {
const result = await client.search({
index: constant.index,
size: 9999,
query: {
match_all: {}
}
}, { asStream: true })
res.writeHead(200, {
'Content-Type': 'application/x-gzip',
'Content-disposition': 'attachment; filename=fediblock-index.json.gz'
})
result.pipe(zlib.createGzip()).pipe(res, { end: true })
} else {
res.status(404).end()
}
})
} }

View File

@ -148,10 +148,8 @@ module.exports = async (client, apex, app) => {
console.error(e) console.error(e)
} }
} }
global.gc()
yield 0 yield 0
} catch (e) { } catch (e) {
global.gc()
console.error(e) console.error(e)
yield 1 yield 1
} }
@ -220,7 +218,6 @@ module.exports = async (client, apex, app) => {
} }
}, },
scanReturn = async () => { scanReturn = async () => {
global.gc()
app.locals.scannum = 0 app.locals.scannum = 0
if (servers && servers.length > 0) { if (servers && servers.length > 0) {
return await scan(servers.shift()) return await scan(servers.shift())

View File

@ -9,7 +9,7 @@
}, },
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"start": "node --max-old-space-size=1024 --expose-gc server.js", "start": "node --max-old-space-size=1024 server.js",
"build": "rm -rf dist/* && parcel build public/index.html --no-source-maps --dist-dir dist/", "build": "rm -rf dist/* && parcel build public/index.html --no-source-maps --dist-dir dist/",
"install": "cd node_modules && rm -rf http-signature && rm -rf request/node_modules/http-signature && mv @peertube/http-signature ." "install": "cd node_modules && rm -rf http-signature && rm -rf request/node_modules/http-signature && mv @peertube/http-signature ."
}, },