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) => {
const constant = require('./constant'),
zlib = require('zlib'),
clean = str => {
return str.replace(/[\/\\^$+?()`'¡¿¨!"·%&=;,\|\[\]{}]+/gmi, '')
}
@ -476,7 +477,6 @@ module.exports = (app, client) => {
instancescomment = instances.map(i => ({
instance: i._source.instance, comment: i._source.blocks.find(block => block.domain === clean(req.params.instance)).comment
}))
global.gc()
res.json({
block_count: instances.length,
instances: instancescomment,
@ -486,4 +486,34 @@ module.exports = (app, client) => {
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)
}
}
global.gc()
yield 0
} catch (e) {
global.gc()
console.error(e)
yield 1
}
@ -220,7 +218,6 @@ module.exports = async (client, apex, app) => {
}
},
scanReturn = async () => {
global.gc()
app.locals.scannum = 0
if (servers && servers.length > 0) {
return await scan(servers.shift())

View File

@ -9,7 +9,7 @@
},
"license": "MIT",
"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/",
"install": "cd node_modules && rm -rf http-signature && rm -rf request/node_modules/http-signature && mv @peertube/http-signature ."
},