mirror of
https://github.com/pockethost/pockethost.git
synced 2025-11-24 14:35:49 +00:00
fix: db compaction
This commit is contained in:
parent
b7d9badd7c
commit
a0df601f96
@ -1,18 +1,34 @@
|
|||||||
import { exec } from 'child_process'
|
import { execSync } from 'child_process'
|
||||||
import { globSync } from 'glob'
|
import { globSync } from 'glob'
|
||||||
import { DATA_ROOT } from '../../../../core'
|
import { DATA_ROOT } from '../../../../core'
|
||||||
import { logger } from '../../../common/Logger'
|
import { logger } from '../../../common/Logger'
|
||||||
|
|
||||||
export const compact = async () => {
|
export const compact = async () => {
|
||||||
const { info } = logger()
|
const { info, error } = logger()
|
||||||
|
|
||||||
const files = [`data`, `logs`].flatMap((db) =>
|
const files = [
|
||||||
globSync(`${DATA_ROOT()}/*/pb_data/${db}.db{-shm,-wal}`),
|
...new Set(
|
||||||
)
|
[`data`, `logs`].flatMap((db) =>
|
||||||
|
globSync(`${DATA_ROOT()}/*/pb_data/${db}.db{-shm,-wal}`).map((f) =>
|
||||||
|
f.replace(/-(?:shm|wal)$/, ''),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
files.map(async (file) => {
|
info(`Compacting ${files.length} files`, { files })
|
||||||
info(`Compacting ${file}`)
|
|
||||||
exec(`sqlite3 ${file} ".tables"`)
|
files.forEach((file) => {
|
||||||
|
const { info, error } = logger().child(file)
|
||||||
|
const cmd = `sqlite3 ${file} ".tables"`
|
||||||
|
info(cmd)
|
||||||
|
try {
|
||||||
|
execSync(cmd)
|
||||||
|
info(`Finished compacting`)
|
||||||
|
} catch (e) {
|
||||||
|
error(`Error compacting`, e)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
// console.log('Compaction complete')
|
||||||
info(`Compaction complete`)
|
info(`Compaction complete`)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user