Skip to content

Commit

Permalink
Do not left loki open
Browse files Browse the repository at this point in the history
  • Loading branch information
Ale Figueroa committed Mar 5, 2019
1 parent 450b794 commit 3451f72
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ export class Recorder {
async save (request: SerializedRequest, response: SerializedResponse) {
const db = await this.db
const tapes = db.addCollection<FullSerializedRequest>('tapes', { disableMeta: true })
return tapes.add({ ...request, response })
const tape = tapes.add({ ...request, response })
db.saveDatabase()
return tape
}

async read (req: IncomingMessage, body: Buffer) {
Expand Down
2 changes: 1 addition & 1 deletion src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function getDB (opts: YakTimeOpts): Promise<Loki> {
if (db == null) {
const dbPath = path.join(opts.dirname, 'tapes.json')
debug(`Opening db on ${dbPath}`)
db = new Loki(dbPath, { autoload: true, autosave: true })
db = new Loki(dbPath, { autoload: true, autosave: false, throttledSaves: true, verbose: process.env.DEBUG != null })
}
return db
}

0 comments on commit 3451f72

Please sign in to comment.