This commit is contained in:
vss-devel 2019-02-26 20:34:23 +03:00
parent 3cb9420b45
commit 481ddaa58e

View File

@ -326,7 +326,7 @@ class Writer {
write ( data ) { write ( data ) {
return this.queue.acquire() return this.queue.acquire()
.then( token => { .then( token => {
const result = this.position const startPosition = this.position
this.position += data.length this.position += data.length
const saturated = ! this.stream.write( data ) const saturated = ! this.stream.write( data )
@ -335,7 +335,7 @@ class Writer {
} else { } else {
this.queue.release( token ) this.queue.release( token )
} }
return result return startPosition
}) })
} }
@ -655,18 +655,18 @@ class Item {
this.dirEntryOffset = await out.write( chunksToBuffer( chunks )) this.dirEntryOffset = await out.write( chunksToBuffer( chunks ))
log( 'storeDirEntry done', this.dirEntryOffset, this.path ) log( 'storeDirEntry done', this.dirEntryOffset, this.path )
return this.saveDirEntryIndex( this.dirEntry ) return this.saveDirEntryIndex()
} }
async saveDirEntryIndex ( offset ) { async saveDirEntryIndex ( ) {
const id = await this.getId() const id = await this.getId()
try { try {
log( 'saveDirEntryIndex', id, offset, this.path ) log( 'saveDirEntryIndex', id, this.dirEntryOffset, this.path )
return await wikiDb.run( return await wikiDb.run(
'INSERT INTO dirEntries (id, offset) VALUES (?,?)', 'INSERT INTO dirEntries (id, offset) VALUES (?,?)',
[ [
id, id,
offset, this.dirEntryOffset,
] ]
) )
} catch ( err ) { } catch ( err ) {
@ -1329,15 +1329,15 @@ async function storeUrlIndex () {
async function storeTitleIndex () { async function storeTitleIndex () {
header.titlePtrPos = await saveIndex ({ header.titlePtrPos = await saveIndex ({
query: query: `
'SELECT ' + SELECT
'titleKey, ' + titleKey,
'urlSorted.rowid - 1 AS articleNumber ' + urlSorted.rowid - 1 AS articleNumber
'FROM urlSorted ' + FROM urlSorted
'JOIN articles ' + JOIN articles
'USING (id) ' + USING (id)
'ORDER BY titleKey ' + ORDER BY titleKey
';', ;`,
byteLength: 4, byteLength: 4,
count: header.articleCount, count: header.articleCount,
logPrefix: 'storeTitleIndex', logPrefix: 'storeTitleIndex',
@ -1401,7 +1401,7 @@ function getHeader () {
async function storeHeader() { async function storeHeader() {
var buf = Buffer.concat([ getHeader(), getMimeTypes() ]) var buf = Buffer.concat([ getHeader(), getMimeTypes() ])
var fd = await fs.open( outPath, 'r+' ) var fd = await fs.open( outPath, 'r+' )
await fs.writeSync( fd, buf, 0, buf.length, 0 ) await fs.write( fd, buf, 0, buf.length, 0 )
return fs.close( fd ) return fs.close( fd )
} }