mirror of
https://github.com/documenso/documenso.git
synced 2026-07-24 17:04:12 +10:00
fix: show current month data and add caching (#2573)
### Summary - Add Cache-Control headers to all route responses (1h s-maxage, 2h stale-while-revalidate) - Append current month to chart data so graphs stay up-to-date (cumulative carries forward, else zero) - Remove `.limit(12)` from growth queries for full history - Pass isCumulative flag through addZeroMonth - Deduplicate TransformedData type, remove transformRepoStats
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
import { addZeroMonth } from './add-zero-month';
|
||||
import { type TransformedData, addZeroMonth } from './add-zero-month';
|
||||
|
||||
type MetricKeys = {
|
||||
stars: number;
|
||||
@@ -14,14 +14,6 @@ type DataEntry = {
|
||||
[key: string]: MetricKeys;
|
||||
};
|
||||
|
||||
type TransformData = {
|
||||
labels: string[];
|
||||
datasets: {
|
||||
label: string;
|
||||
data: number[];
|
||||
}[];
|
||||
};
|
||||
|
||||
type MetricKey = keyof MetricKeys;
|
||||
|
||||
const FRIENDLY_METRIC_NAMES: { [key in MetricKey]: string } = {
|
||||
@@ -38,7 +30,7 @@ export function transformData({
|
||||
}: {
|
||||
data: DataEntry;
|
||||
metric: MetricKey;
|
||||
}): TransformData {
|
||||
}): TransformedData {
|
||||
try {
|
||||
if (!data || Object.keys(data).length === 0) {
|
||||
return {
|
||||
@@ -103,7 +95,7 @@ export function transformData({
|
||||
],
|
||||
};
|
||||
|
||||
return addZeroMonth(transformedData);
|
||||
return addZeroMonth(transformedData, true);
|
||||
} catch (error) {
|
||||
return {
|
||||
labels: [],
|
||||
@@ -111,6 +103,3 @@ export function transformData({
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// To be on the safer side
|
||||
export const transformRepoStats = transformData;
|
||||
|
||||
Reference in New Issue
Block a user