Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions relay_worker/src/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export class SessionRelay extends DurableObject<Env> {
/** Write-through caches (populated on first access, lost on hibernation). */
private _lastActivity?: number;
private _handledRequests?: Record<string, number>;
private _fcmToken?: string;
private _fcmToken?: string | null; // undefined=unchecked, null=checked-no-token, string=token

constructor(ctx: DurableObjectState, env: Env) {
super(ctx, env); // REQUIRED for hibernation — sets this.ctx + this.env
Expand Down Expand Up @@ -1081,12 +1081,18 @@ export class SessionRelay extends DurableObject<Env> {
if (fcmToken) {
this._fcmToken = fcmToken;
await this.ctx.storage.put('fcmToken', fcmToken);
} else {
this._fcmToken = null; // Cache the miss — prevents KV reads on every message
}
} else {
this._fcmToken = fcmToken;
}
}
if (!fcmToken) return false;
if (!fcmToken) {
// Write cooldown even on miss — protects across DO hibernation boundaries
await this.ctx.storage.put('lastPushTimestamp', now);
return false;
}

await this.ctx.storage.put('lastPushTimestamp', now);

Expand Down