Skip to content

Commit 5afdd9b

Browse files
committed
Emit whether or not the triple counts are exact in the metadata callback
1 parent d700872 commit 5afdd9b

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

lib/datasources/CompositeDatasource.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,28 @@ CompositeDatasource.prototype._getDatasourceInfo = function(query, absoluteOffse
6262
offset: 0, limit: 1,
6363
subject: query.subject, predicate: query.predicate, object: query.object
6464
};
65-
return findRecursive(0, absoluteOffset, -1, -1, 0, cb);
65+
return findRecursive(0, absoluteOffset, -1, -1, 0, cb, true);
6666

67-
function findRecursive(datasourceIndex, offset, chosenDatasource, chosenOffset, totalCount) {
67+
function findRecursive(datasourceIndex, offset, chosenDatasource, chosenOffset, totalCount, exactCount) {
6868
if (datasourceIndex >= self._datasourceNames.length) {
6969
// We checked all datasources, return our accumulated information
70-
cb(chosenDatasource, chosenOffset, totalCount);
70+
cb(chosenDatasource, chosenOffset, totalCount, exactCount);
7171
} else {
7272
var emptyTripleStream = { push: noop };
7373
self._getDatasourceById(datasourceIndex)._executeQuery(emptyQuery, emptyTripleStream, function (metadata) {
7474
var count = metadata.totalCount;
75+
var exact = metadata.exactCount;
7576
if (chosenDatasource < 0 && offset < count) {
7677
// We can start querying from this datasource
7778
setImmediate(function () {
78-
findRecursive(datasourceIndex + 1, offset - count, datasourceIndex, offset, totalCount + count);
79+
findRecursive(datasourceIndex + 1, offset - count, datasourceIndex, offset,
80+
totalCount + count, exactCount && exact);
7981
});
8082
} else {
8183
// We forward our accumulated information and go check the next datasource
8284
setImmediate(function () {
83-
findRecursive(datasourceIndex + 1, offset - count, chosenDatasource, chosenOffset, totalCount + count);
85+
findRecursive(datasourceIndex + 1, offset - count, chosenDatasource, chosenOffset,
86+
totalCount + count, exactCount && exact);
8487
});
8588
}
8689
});
@@ -94,14 +97,14 @@ function noop() {}
9497
CompositeDatasource.prototype._executeQuery = function (query, tripleStream, metadataCallback) {
9598
var offset = query.offset || 0, limit = query.limit || Infinity;
9699
var self = this;
97-
this._getDatasourceInfo(query, offset, function(datasourceIndex, relativeOffset, totalCount) {
100+
this._getDatasourceInfo(query, offset, function(datasourceIndex, relativeOffset, totalCount, exactCount) {
98101
if (datasourceIndex < 0) {
99102
// No valid datasource has been found
100-
metadataCallback({ totalCount: totalCount });
103+
metadataCallback({ totalCount: totalCount, exactCount: exactCount });
101104
tripleStream.push(null);
102105
} else {
103106
// Send query to first applicable datasource and optionally emit triples from consecutive datasources
104-
metadataCallback({ totalCount: totalCount });
107+
metadataCallback({ totalCount: totalCount, exactCount: exactCount });
105108
var emitted = 0;
106109

107110
// Modify our triple stream so that if all results from one datasource have arrived,

lib/datasources/ExternalHdtDatasource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ ExternalHdtDatasource.prototype._executeQuery = function (query, tripleStream, m
5353
// Ensure the estimated total count is as least as large as the number of triples
5454
if (tripleCount && estimatedTotalCount < offset + tripleCount)
5555
estimatedTotalCount = offset + (tripleCount < query.limit ? tripleCount : 2 * tripleCount);
56-
metadataCallback({ totalCount: estimatedTotalCount });
56+
metadataCallback({ totalCount: estimatedTotalCount, exactCount: false });
5757
tripleStream.push(null);
5858
}
5959
});

lib/datasources/HdtDatasource.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ HdtDatasource.prototype._initialize = function (done) {
3333
HdtDatasource.prototype._executeQuery = function (query, tripleStream, metadataCallback) {
3434
this._hdtDocument.search(query.subject, query.predicate, query.object,
3535
{ limit: query.limit, offset: query.offset },
36-
function (error, triples, estimatedTotalCount) {
36+
function (error, triples, estimatedTotalCount, exactCount) {
3737
if (error) return tripleStream.emit('error', error);
3838
// Ensure the estimated total count is as least as large as the number of triples
3939
var tripleCount = triples.length, offset = query.offset || 0;
4040
if (tripleCount && estimatedTotalCount < offset + tripleCount)
4141
estimatedTotalCount = offset + (tripleCount < query.limit ? tripleCount : 2 * tripleCount);
42-
metadataCallback({ totalCount: estimatedTotalCount });
42+
metadataCallback({ totalCount: estimatedTotalCount, exactCount: exactCount });
4343
// Add the triples to the stream
4444
for (var i = 0; i < tripleCount; i++)
4545
tripleStream.push(triples[i]);

lib/datasources/MemoryDatasource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ MemoryDatasource.prototype._executeQuery = function (query, tripleStream, metada
2929
var offset = query.offset || 0, limit = query.limit || Infinity,
3030
triples = this._tripleStore.findByIRI(query.subject, query.predicate, query.object);
3131
// Send the metadata
32-
metadataCallback({ totalCount: triples.length });
32+
metadataCallback({ totalCount: triples.length, exactCount: true });
3333
// Send the requested subset of triples
3434
for (var i = offset, l = Math.min(offset + limit, triples.length); i < l; i++)
3535
tripleStream.push(triples[i]);

lib/datasources/SparqlDatasource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ SparqlDatasource.prototype._executeQuery = function (query, tripleStream, metada
5555
// Determine the total number of matching triples
5656
this._getPatternCount(sparqlPattern, function (error, totalCount) {
5757
if (error) emitError(error);
58-
else if (typeof totalCount === 'number') metadataCallback({ totalCount: totalCount });
58+
else if (typeof totalCount === 'number') metadataCallback({ totalCount: totalCount, exactCount: true });
5959
});
6060

6161
// Emits an error on the triple stream

0 commit comments

Comments
 (0)