mirror of
https://github.com/outline/outline.git
synced 2025-03-14 10:07:11 +00:00
Specify time conversion unit (#7458)
* fix: specificity in time units * fix: milliseconds -> ms
This commit is contained in:
@ -16,7 +16,7 @@ let isReloaded = false;
|
||||
export default function useAutoRefresh() {
|
||||
const [minutes, setMinutes] = React.useState(0);
|
||||
const isVisible = usePageVisibility();
|
||||
const isIdle = useIdle(15 * Minute);
|
||||
const isIdle = useIdle(15 * Minute.ms);
|
||||
|
||||
useInterval(() => {
|
||||
setMinutes((prev) => prev + 1);
|
||||
@ -39,5 +39,5 @@ export default function useAutoRefresh() {
|
||||
window.location.reload();
|
||||
isReloaded = true;
|
||||
}
|
||||
}, Minute);
|
||||
}, Minute.ms);
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ const activityEvents = [
|
||||
* @returns boolean if the user is idle
|
||||
*/
|
||||
export default function useIdle(
|
||||
timeToIdle: number = 3 * Minute,
|
||||
timeToIdle: number = 3 * Minute.ms,
|
||||
events = activityEvents
|
||||
) {
|
||||
const isMounted = useIsMounted();
|
||||
|
@ -53,7 +53,7 @@ function useShowTime(
|
||||
|
||||
return (
|
||||
!msSincePreviousComment ||
|
||||
(msSincePreviousComment > 15 * Minute &&
|
||||
(msSincePreviousComment > 15 * Minute.ms &&
|
||||
previousTimeStamp !== currentTimeStamp)
|
||||
);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ if (enabled) {
|
||||
},
|
||||
{
|
||||
type: Hook.UnfurlProvider,
|
||||
value: { unfurl: GitHub.unfurl, cacheExpiry: Minute / 1000 },
|
||||
value: { unfurl: GitHub.unfurl, cacheExpiry: Minute.seconds },
|
||||
},
|
||||
{
|
||||
type: Hook.Uninstall,
|
||||
|
@ -19,7 +19,7 @@ if (enabled) {
|
||||
PluginManager.add([
|
||||
{
|
||||
type: Hook.UnfurlProvider,
|
||||
value: { unfurl: Iframely.unfurl, cacheExpiry: Day / 1000 },
|
||||
value: { unfurl: Iframely.unfurl, cacheExpiry: Day.seconds },
|
||||
|
||||
// Make sure this is last in the stack to be evaluated after all other unfurl providers
|
||||
priority: PluginPriority.VeryLow,
|
||||
|
@ -104,7 +104,7 @@ export default class SlackProcessor extends BaseProcessor {
|
||||
if (
|
||||
event.name === "revisions.create" &&
|
||||
differenceInMilliseconds(document.updatedAt, document.publishedAt) <
|
||||
Minute
|
||||
Minute.ms
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ export class ViewsExtension implements Extension {
|
||||
const lastUpdate = this.lastViewBySocket.get(socketId);
|
||||
const [, documentId] = documentName.split(".");
|
||||
|
||||
if (!lastUpdate || Date.now() - lastUpdate.getTime() > Minute) {
|
||||
if (!lastUpdate || Date.now() - lastUpdate.getTime() > Minute.ms) {
|
||||
this.lastViewBySocket.set(socketId, new Date());
|
||||
|
||||
Logger.debug(
|
||||
|
@ -77,7 +77,7 @@ export default class CommentCreatedEmail extends BaseEmail<
|
||||
content = await TextHelper.attachmentsToSignedUrls(
|
||||
content,
|
||||
document.teamId,
|
||||
(4 * Day) / 1000
|
||||
4 * Day.seconds
|
||||
);
|
||||
|
||||
if (content) {
|
||||
|
@ -69,7 +69,7 @@ export default class CommentMentionedEmail extends BaseEmail<
|
||||
content = await TextHelper.attachmentsToSignedUrls(
|
||||
content,
|
||||
document.teamId,
|
||||
(4 * Day) / 1000
|
||||
4 * Day.seconds
|
||||
);
|
||||
|
||||
if (content) {
|
||||
|
@ -68,7 +68,7 @@ export default class DocumentPublishedOrUpdatedEmail extends BaseEmail<
|
||||
const content = await DocumentHelper.toEmailDiff(before, revision, {
|
||||
includeTitle: false,
|
||||
centered: false,
|
||||
signedUrls: (4 * Day) / 1000,
|
||||
signedUrls: 4 * Day.seconds,
|
||||
baseUrl: props.teamUrl,
|
||||
});
|
||||
|
||||
|
@ -35,6 +35,6 @@ export default class HealthMonitor {
|
||||
}
|
||||
);
|
||||
}
|
||||
}, 30 * Second);
|
||||
}, 30 * Second.ms);
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ export default class EmailsProcessor extends BaseProcessor {
|
||||
},
|
||||
{ notificationId }
|
||||
).schedule({
|
||||
delay: Minute,
|
||||
delay: Minute.ms,
|
||||
});
|
||||
return;
|
||||
}
|
||||
@ -76,7 +76,7 @@ export default class EmailsProcessor extends BaseProcessor {
|
||||
},
|
||||
{ notificationId }
|
||||
).schedule({
|
||||
delay: Minute,
|
||||
delay: Minute.ms,
|
||||
});
|
||||
return;
|
||||
}
|
||||
@ -107,7 +107,7 @@ export default class EmailsProcessor extends BaseProcessor {
|
||||
},
|
||||
{ notificationId: notification.id }
|
||||
).schedule({
|
||||
delay: Minute,
|
||||
delay: Minute.ms,
|
||||
});
|
||||
return;
|
||||
}
|
||||
@ -122,7 +122,7 @@ export default class EmailsProcessor extends BaseProcessor {
|
||||
},
|
||||
{ notificationId: notification.id }
|
||||
).schedule({
|
||||
delay: Minute,
|
||||
delay: Minute.ms,
|
||||
});
|
||||
return;
|
||||
}
|
||||
@ -139,7 +139,7 @@ export default class EmailsProcessor extends BaseProcessor {
|
||||
},
|
||||
{ notificationId: notification.id }
|
||||
).schedule({
|
||||
delay: Minute,
|
||||
delay: Minute.ms,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ export function createQueue(
|
||||
setInterval(async () => {
|
||||
Metrics.gauge(`${prefix}.count`, await queue.count());
|
||||
Metrics.gauge(`${prefix}.delayed_count`, await queue.getDelayedCount());
|
||||
}, 5 * Second);
|
||||
}, 5 * Second.ms);
|
||||
}
|
||||
|
||||
ShutdownHelper.add(name, ShutdownOrder.normal, async () => {
|
||||
|
@ -35,7 +35,7 @@ router.use(["/images/*", "/email/*", "/fonts/*"], async (ctx, next) => {
|
||||
done = await send(ctx, ctx.path, {
|
||||
root: path.resolve(__dirname, "../../../public"),
|
||||
// 7 day expiry, these assets are mostly static but do not contain a hash
|
||||
maxAge: Day * 7,
|
||||
maxAge: Day.ms * 7,
|
||||
setHeaders: (res) => {
|
||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||
},
|
||||
@ -71,7 +71,7 @@ if (env.isProduction) {
|
||||
await send(ctx, pathname, {
|
||||
root: path.join(__dirname, "../../app/"),
|
||||
// Hashed static assets get 1 year expiry plus immutable flag
|
||||
maxAge: Day * 365,
|
||||
maxAge: Day.ms * 365,
|
||||
immutable: true,
|
||||
setHeaders: (res) => {
|
||||
res.setHeader("Service-Worker-Allowed", "/");
|
||||
@ -105,7 +105,7 @@ router.get("/locales/:lng.json", async (ctx) => {
|
||||
await send(ctx, path.join(lng, "translation.json"), {
|
||||
setHeaders: (res, _, stats) => {
|
||||
res.setHeader("Last-Modified", formatRFC7231(stats.mtime));
|
||||
res.setHeader("Cache-Control", `public, max-age=${(7 * Day) / 1000}`);
|
||||
res.setHeader("Cache-Control", `public, max-age=${7 * Day.seconds}`);
|
||||
res.setHeader(
|
||||
"ETag",
|
||||
crypto.createHash("md5").update(stats.mtime.toISOString()).digest("hex")
|
||||
@ -121,7 +121,7 @@ router.get("/robots.txt", (ctx) => {
|
||||
|
||||
router.get("/opensearch.xml", (ctx) => {
|
||||
ctx.type = "text/xml";
|
||||
ctx.response.set("Cache-Control", `public, max-age=${(7 * Day) / 1000}`);
|
||||
ctx.response.set("Cache-Control", `public, max-age=${7 * Day.seconds}`);
|
||||
ctx.body = opensearchResponse(ctx.request.URL.origin);
|
||||
});
|
||||
|
||||
|
@ -12,13 +12,13 @@ export default function init() {
|
||||
}
|
||||
}
|
||||
|
||||
setInterval(() => void run(TaskSchedule.Daily), Day);
|
||||
setInterval(() => void run(TaskSchedule.Hourly), Hour);
|
||||
setInterval(() => void run(TaskSchedule.Daily), Day.ms);
|
||||
setInterval(() => void run(TaskSchedule.Hourly), Hour.ms);
|
||||
|
||||
// Just give everything time to startup before running the first time. Not
|
||||
// _technically_ required to function.
|
||||
setTimeout(() => {
|
||||
void run(TaskSchedule.Daily);
|
||||
void run(TaskSchedule.Hourly);
|
||||
}, 30 * Second);
|
||||
}, 30 * Second.ms);
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ export default function init(app: Koa = new Koa(), server?: Server) {
|
||||
}
|
||||
Metrics.gaugePerInstance("connections.count", count);
|
||||
});
|
||||
}, 5 * Second);
|
||||
}, 5 * Second.ms);
|
||||
}
|
||||
|
||||
ShutdownHelper.add("connections", ShutdownOrder.normal, async () => {
|
||||
|
@ -7,7 +7,7 @@ import Redis from "@server/storage/redis";
|
||||
*/
|
||||
export class CacheHelper {
|
||||
// Default expiry time for cache data in seconds
|
||||
private static defaultDataExpiry = Day / 1000;
|
||||
private static defaultDataExpiry = Day.seconds;
|
||||
|
||||
/**
|
||||
* Given a key, gets the data from cache store
|
||||
|
@ -1,11 +1,29 @@
|
||||
/** A second in ms */
|
||||
export const Second = 1000;
|
||||
export class Second {
|
||||
/** Milliseconds in a second */
|
||||
public static ms = 1000;
|
||||
}
|
||||
|
||||
/** A minute in ms */
|
||||
export const Minute = 60 * Second;
|
||||
export class Minute {
|
||||
/** Milliseconds in a minute */
|
||||
public static ms = 60 * Second.ms;
|
||||
/** Seconds in a minute */
|
||||
public static seconds = 60;
|
||||
}
|
||||
|
||||
/** An hour in ms */
|
||||
export const Hour = 60 * Minute;
|
||||
export class Hour {
|
||||
/** Milliseconds in an hour */
|
||||
public static ms = 60 * Minute.ms;
|
||||
/** Seconds in an hour */
|
||||
public static seconds = 60 * Minute.seconds;
|
||||
/** Minutes in an hour */
|
||||
public static minutes = 60;
|
||||
}
|
||||
|
||||
/** A day in ms */
|
||||
export const Day = 24 * Hour;
|
||||
export class Day {
|
||||
/** Milliseconds in a day */
|
||||
public static ms = 24 * Hour.ms;
|
||||
/** Seconds in a day */
|
||||
public static seconds = 24 * Hour.seconds;
|
||||
/** Minutes in a day */
|
||||
public static minutes = 24 * Hour.minutes;
|
||||
}
|
||||
|
Reference in New Issue
Block a user