Files
outline/server/models/DocumentInsight.ts
T
Tom Moor 600108bc43 feat: Document insight rollups (#12086)
* First pass

* Remove popularity changes

* Address review feedback

- Compute retention cutoff in UTC from the database rather than worker-local TZ
- Push partition predicate into rollup source CTEs to avoid full-table scans per partition

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* Anchor insight rollups to UTC and include today

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-18 08:11:15 -04:00

73 lines
1.4 KiB
TypeScript

import type { InferAttributes, InferCreationAttributes } from "sequelize";
import {
BelongsTo,
Column,
DataType,
Default,
ForeignKey,
Table,
} from "sequelize-typescript";
import Document from "./Document";
import Team from "./Team";
import IdModel from "./base/IdModel";
import { SkipChangeset } from "./decorators/Changeset";
import Fix from "./decorators/Fix";
@Table({ tableName: "document_insights", modelName: "documentInsight" })
@Fix
class DocumentInsight extends IdModel<
InferAttributes<DocumentInsight>,
Partial<InferCreationAttributes<DocumentInsight>>
> {
@Column(DataType.DATEONLY)
date: string;
@Default(0)
@Column(DataType.INTEGER)
@SkipChangeset
viewCount: number;
@Default(0)
@Column(DataType.INTEGER)
@SkipChangeset
viewerCount: number;
@Default(0)
@Column(DataType.INTEGER)
@SkipChangeset
commentCount: number;
@Default(0)
@Column(DataType.INTEGER)
@SkipChangeset
reactionCount: number;
@Default(0)
@Column(DataType.INTEGER)
@SkipChangeset
revisionCount: number;
@Default(0)
@Column(DataType.INTEGER)
@SkipChangeset
editorCount: number;
// associations
@BelongsTo(() => Document, "documentId")
document: Document;
@ForeignKey(() => Document)
@Column(DataType.UUID)
documentId: string;
@BelongsTo(() => Team, "teamId")
team: Team;
@ForeignKey(() => Team)
@Column(DataType.UUID)
teamId: string;
}
export default DocumentInsight;