-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sendto(getHistory) not returning the oldest value #331
Comments
Selects
Selects |
Another test. Looks like the last record of the first day in selected range is returned (instead the first one). But just if the number of stored values is larger than
const objId = '0_userdata.0.test_history2';
const startTs = new Date(2024, 4, 1, 11, 12, 13);
const stepSize = 60 * 60 * 4 * 1000; // 4 hours
const generateRows = 961; // CHANGE THIS to 961 (or higher)
async function createTestData(count) {
let testData = [];
let ts = startTs.getTime();
let storedValueCnt = 0;
for (let i = 0; i < count; i++) {
ts = startTs.getTime() + (stepSize * i);
testData.push({ ts, val: i, ack: true, from: 'system.adapter.javascript.0' });
if (testData.length % 100 === 0) {
await sendToAsync('history.0', 'storeState', {
id: objId,
state: testData,
});
storedValueCnt += testData.length;
testData = [];
}
}
if (testData.length > 0) {
await sendToAsync('history.0', 'storeState', {
id: objId,
state: testData,
});
storedValueCnt += testData.length;
}
console.warn(`Generated test data: ${storedValueCnt} items, from ${formatDate(startTs.getTime(), 'DD.MM.YYYY hh:mm:ss.sss')} to ${formatDate(ts, 'DD.MM.YYYY hh:mm:ss.sss')}`);
return ts;
}
async function testSelectData(endTs) {
// THIS IS WORKING
const testLimit = 1000;
const getHistoryResult = await sendToAsync('history.0', 'getHistory', {
id: objId,
options: {
start: startTs.getTime(),
end: endTs,
aggregate: 'none',
limit: testLimit,
returnNewestEntries: false,
ignoreNull: true,
addId: true,
from: true,
ack: true,
q: true,
}
});
const firstRecord = getHistoryResult?.result[0];
if (firstRecord.ts !== startTs.getTime()) {
console.warn(`Oldest record result for ${objId}: ${JSON.stringify(firstRecord)} -> ${formatDate(firstRecord.ts, 'DD.MM.YYYY hh:mm:ss.sss')} (should be ${formatDate(startTs.getTime(), 'DD.MM.YYYY hh:mm:ss.sss')})`);
}
// THIS IS NOT WORKING (limit too low?)
const getOldestResult = await sendToAsync('history.0', 'getHistory', {
id: objId,
options: {
start: 1,
end: endTs,
aggregate: 'none',
limit: 1,
returnNewestEntries: false,
ignoreNull: true,
}
});
const singleRecord = getOldestResult?.result[0];
if (singleRecord.ts !== startTs.getTime()) {
console.warn(`Oldest record result for ${objId}: ${JSON.stringify(singleRecord)} -> ${formatDate(singleRecord.ts, 'DD.MM.YYYY hh:mm:ss.sss')} (should be ${formatDate(startTs.getTime(), 'DD.MM.YYYY hh:mm:ss.sss')})`);
}
}
createState(objId, { type: 'number', read: true, write: true }, async () => {
await sendToAsync('history.0', 'enableHistory', {
id: objId,
options: {
enabled: true,
aliasId: '',
debounceTime: 0,
blockTime: 0,
changesOnly: true,
changesRelogInterval: 0,
changesMinDelta: 0,
ignoreBelowNumber: '',
disableSkippedValueLogging: false,
retention: 31536000,
customRetentionDuration: 365,
maxLength: 960,
enableDebugLogs: true,
debounce: 0,
}
});
const enabledDps = await sendToAsync('history.0', 'getEnabledDPs', {});
console.log(`Logging is active for ${Object.keys(enabledDps).join(', ')}`);
if (Object.keys(enabledDps).includes(objId)) {
// Delete previous data
const deleteAllResult = await sendToAsync('history.0', 'deleteAll', [{ id: objId }]);
console.log(`Deleted all saved values of ${objId}: ${deleteAllResult?.success}`);
// Save new test data
const endTs = await createTestData(generateRows);
// loop for development
setInterval(async () => {
testSelectData(endTs);
}, 2000);
} else {
console.error(`Logging not activated for ${objId}`);
}
}); |
Describe the bug
A clear and concise description of what the bug is.
To Reproduce
Check the following script. It writes a number given of records into the database and tries to find the oldest timestamp afterwards (with value 0).
It's working if less that 961 records have been generated (in this case). Otherwise it returns the value "23".
Versions:
The text was updated successfully, but these errors were encountered: