Skip to content

Commit

Permalink
v1.4.2 hotfix for a race condition on time caching
Browse files Browse the repository at this point in the history
  • Loading branch information
mbehr1 committed Apr 29, 2020
1 parent 375c6ee commit 1b58f4a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to the "smart-log" extension will be documented in this file

<!-- Check [Keep a Changelog](http:https://keepachangelog.com/) for recommendations on how to structure this file. -->

## [1.4.2]
- Hotfix for the race condition (multiple entrance) of provideTimeByData.

## [1.4.1]
- Added some console logs to find a bug where sometimes hover times are wrong.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "smart-log",
"displayName": "Smart-Log",
"description": "Provides analysis and visualization features for text based log files.",
"version": "1.4.1",
"version": "1.4.2",
"license": "CC BY-NC-SA 4.0",
"publisher": "mbehr1",
"author": {
Expand Down
18 changes: 12 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,15 +442,20 @@ export default class SmartLogs implements vscode.TreeDataProvider<EventNode>, vs

console.log(`smart-log.provideTimeByData regenerating cachedTimes. line=${line}/${data.doc.lineCount} vs. cachedTimes.lines=${data.cachedTimes?.length}`);

// we reset the times here in any case:
// there is a race cond here that this function gets called multiple times (as the function calls sleep...)
// so as hotfix we do change the cachedTimes array only once all calculated.
// proper fix pending.
data.cachedTimes = undefined;

return vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, cancellable: true }, async (progress, cancelToken): Promise<Date> => {

let d3TimeParser = null;
if (data.timeFormat) {
d3TimeParser = d3.timeParse(data.timeFormat);
}

// we reset the times here in any case:
data.cachedTimes = new Array<Date>();
let cachedTimes = new Array<Date>();

// calc times for full document here (we could calc only for 0-pos.line...)
// for each line provide time from current or lines above that have a time.
Expand All @@ -477,7 +482,7 @@ export default class SmartLogs implements vscode.TreeDataProvider<EventNode>, vs
if (year < 100) { year += 2000; }
const ms: number = regRes[7] ? +regRes[7] : 0;
let date = new Date(year, +regRes[2] - 1, +regRes[3], +regRes[4], +regRes[5], +regRes[6], ms);
data.cachedTimes.push(date);
cachedTimes.push(date);
} else if (regRes.length === 2) { // one complete date string
let date: Date | null = null;
if (d3TimeParser) {
Expand All @@ -491,17 +496,18 @@ export default class SmartLogs implements vscode.TreeDataProvider<EventNode>, vs
} else {
date = new Date(regRes[1]);
}
data.cachedTimes.push(date ? date : new Date(0));
cachedTimes.push(date ? date : new Date(0));
}
} else {
// use the one from prev. line
if (i > 0) {
data.cachedTimes.push(data.cachedTimes[i - 1]);
cachedTimes.push(cachedTimes[i - 1]);
} else {
data.cachedTimes.push(new Date(0));
cachedTimes.push(new Date(0));
}
}
}
data.cachedTimes = cachedTimes;
console.log(`smart-log.provideTime calculated all times. (lines=${data.cachedTimes.length})`);
const toRet = data.cachedTimes[line];
if (data.timeAdjustMs) {
Expand Down

0 comments on commit 1b58f4a

Please sign in to comment.