save index

This commit is contained in:
vss-devel 2019-02-26 20:26:15 +03:00
parent c97d36e1be
commit 845789ea31

View File

@ -308,7 +308,6 @@ function cvsReader ( path, options ) {
class Writer { class Writer {
constructor ( path ) { constructor ( path ) {
this.position = 0 this.position = 0
this.stream = fs.createWriteStream( path, { highWaterMark: 1024*1024*10 }) this.stream = fs.createWriteStream( path, { highWaterMark: 1024*1024*10 })
this.stream.once( 'open', fd => { }) this.stream.once( 'open', fd => { })
this.stream.on( 'error', err => { this.stream.on( 'error', err => {
@ -517,9 +516,12 @@ class ClusterPool {
'ORDER BY id ' + 'ORDER BY id ' +
';', ';',
byteLength: 8, byteLength: 8,
rowField: 'offset',
count: header.clusterCount, count: header.clusterCount,
logInfo: 'storeClusterIndex', logPrefix: 'storeClusterIndex',
rowCb: ( row, index ) => {
return row.offset
},
}) })
} }
@ -1249,26 +1251,20 @@ async function resolveRedirects () {
} }
async function saveIndex ( params ) { async function saveIndex ( params ) {
const logInfo = params.logInfo || 'saveIndex' const logPrefix = params.logPrefix || 'saveIndex'
log( logInfo, 'start', params.count ) const stmt = await wikiDb.prepare( params.query )
let startOffset
var startOffset let i = 0
var stmt = await wikiDb.prepare( params.query )
var i = 0
for ( let row; row = await stmt.get(); i++ ) { for ( let row; row = await stmt.get(); i++ ) {
log( logInfo, i, row ) const val = params.rowCb( row, i )
if ( params.rowCb ) log( logPrefix, i, val, row )
params.rowCb( row, i ) const offset = await out.write( toBuffer( val, params.byteLength ))
var buf = Buffer.alloc( params.byteLength )
writeUIntLE( buf, row[ params.rowField ], 0, params.byteLength )
var offset = await out.write( buf )
if ( ! startOffset ) if ( ! startOffset )
startOffset = offset startOffset = offset
} }
await stmt.finalize() await stmt.finalize()
log( logInfo, 'done', i, params.count, startOffset ) log( logPrefix, 'done', i, params.count, startOffset )
return startOffset return startOffset
} }
@ -1299,12 +1295,12 @@ async function storeUrlIndex () {
'ORDER BY urlSorted.rowid ' + 'ORDER BY urlSorted.rowid ' +
';', ';',
byteLength: 8, byteLength: 8,
rowField: 'offset',
count: header.articleCount, count: header.articleCount,
logInfo: 'storeUrlIndex', logPrefix: 'storeUrlIndex',
rowCb: (row, index) => { rowCb: ( row, index ) => {
if ( row.urlKey == mainPage.urlKey ) if ( row.urlKey == mainPage.urlKey )
mainPage.index = index mainPage.index = index
return row.offset
} }
}) })
} }
@ -1330,9 +1326,11 @@ async function storeTitleIndex () {
'ORDER BY titleKey ' + 'ORDER BY titleKey ' +
';', ';',
byteLength: 4, byteLength: 4,
rowField: 'articleNumber',
count: header.articleCount, count: header.articleCount,
logInfo: 'storeTitleIndex', logPrefix: 'storeTitleIndex',
rowCb: ( row, index ) => {
return row.articleNumber
}
}) })
} }