Skip to content

Commit 26b8a51

Browse files
Merge pull request #109 from ioBroker/feature/44-fix-history-too-big
2 parents 659c7b1 + fb7dede commit 26b8a51

File tree

5 files changed

+198
-108
lines changed

5 files changed

+198
-108
lines changed

express/backend/src/api/adapter.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ router.get("/api/adapter/:name/stats/history", async function (req, res) {
6060
latest: {},
6161
stable: {},
6262
};
63+
const counts: (AdapterVersions & { date: Date })[] = [];
6364
await rawStatistics
6465
.find()
6566
.project<Statistics>({
@@ -72,13 +73,28 @@ router.get("/api/adapter/:name/stats/history", async function (req, res) {
7273
.forEach((s) => {
7374
const stat = unescapeObjectKeys(s);
7475
if (stat.adapters[name]) {
75-
result.counts[stat.date] = {
76+
counts.push({
77+
date: new Date(stat.date),
7678
total: stat.adapters[name],
7779
versions: stat.versions[name],
78-
};
80+
});
7981
}
8082
});
8183

84+
// find all history entries in the given range
85+
const start = new Date((req.query.start as string) ?? 0);
86+
const end = new Date((req.query.end as string) ?? "2999-01-01");
87+
const filtered = counts.filter(
88+
({ date }) => date >= start && date <= end,
89+
);
90+
const minCounts = 100; // return at least 100 items
91+
const modulo = Math.max(1, Math.floor(filtered.length / minCounts));
92+
filtered
93+
.filter((_, i) => i % modulo === 0 || i === filtered.length - 1)
94+
.forEach(({ date, total, versions }) => {
95+
result.counts[date.toISOString()] = { total, versions };
96+
});
97+
8298
// the first version timestamp is wrong (except for new adapters)
8399
let hadFirstLatest = false;
84100
let hadFirstStable = false;
@@ -103,7 +119,19 @@ router.get("/api/adapter/:name/stats/history", async function (req, res) {
103119
}
104120
});
105121

106-
console.log(result);
122+
console.log(
123+
{
124+
name,
125+
start,
126+
end,
127+
total: counts.length,
128+
inRange: filtered.length,
129+
minCounts,
130+
modulo,
131+
returned: Object.keys(result.counts).length,
132+
},
133+
result,
134+
);
107135
if (Object.keys(result.counts).length === 0) {
108136
res.status(404).send("Adapter not found");
109137
return;

express/frontend/package-lock.json

Lines changed: 20 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

express/frontend/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "frontend-newer",
2+
"name": "frontend",
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
@@ -17,7 +17,8 @@
1717
"@types/react-dom": "^18.3.1",
1818
"axios": "^1.7.7",
1919
"clsx": "^2.1.1",
20-
"echarts-for-react": "^3.0.2",
20+
"echarts": "^6.0.0",
21+
"echarts-for-react": "^3.0.4",
2122
"enquirer": "^2.4.1",
2223
"octokit": "^4.0.2",
2324
"react": "^18.3.1",

express/frontend/src/lib/ioBroker.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,24 @@ export async function getCurrentVersions(adapterName: string) {
167167
return result.data;
168168
}
169169

170-
export async function getStatisticsHistory(adapterName: string) {
171-
const result = await axios.get<AdapterStats>(
170+
export async function getStatisticsHistory(
171+
adapterName: string,
172+
start?: Date,
173+
end?: Date,
174+
) {
175+
const url = new URL(
172176
getApiUrl(`adapter/${uc(adapterName)}/stats/history`),
177+
document.location.origin,
173178
);
179+
if (start) {
180+
url.searchParams.set("start", start.toISOString());
181+
}
182+
183+
if (end) {
184+
url.searchParams.set("end", end.toISOString());
185+
}
186+
187+
const result = await axios.get<AdapterStats>(url.toString());
174188
return result.data;
175189
}
176190

0 commit comments

Comments
 (0)