Skip to content
Merged
Show file tree
Hide file tree
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
21 changes: 3 additions & 18 deletions apps/web/actions/spaces/get-user-videos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ export async function getUserVideos(spaceId: Space.SpaceIdOrOrganisationId) {
ownerName: users.name,
folderName: folders.name,
folderColor: folders.color,
effectiveDate: sql<string>`
COALESCE(
JSON_UNQUOTE(JSON_EXTRACT(${videos.metadata}, '$.customCreatedAt')),
${videos.createdAt}
)
`,
effectiveDate: videos.effectiveCreatedAt,
hasActiveUpload: sql`${videoUploads.videoId} IS NOT NULL`.mapWith(
Boolean,
),
Expand Down Expand Up @@ -81,12 +76,7 @@ export async function getUserVideos(spaceId: Space.SpaceIdOrOrganisationId) {
folders.spaceId,
videos.folderId,
)
.orderBy(
desc(sql`COALESCE(
JSON_UNQUOTE(JSON_EXTRACT(${videos.metadata}, '$.customCreatedAt')),
${videos.createdAt}
)`),
)
.orderBy(desc(videos.effectiveCreatedAt))
: await db()
.select(selectFields)
.from(videos)
Expand Down Expand Up @@ -118,12 +108,7 @@ export async function getUserVideos(spaceId: Space.SpaceIdOrOrganisationId) {
folders.spaceId,
videos.folderId,
)
.orderBy(
desc(sql`COALESCE(
JSON_UNQUOTE(JSON_EXTRACT(${videos.metadata}, '$.customCreatedAt')),
${videos.createdAt}
)`),
);
.orderBy(desc(videos.effectiveCreatedAt));

const processedVideoData = videoData.map((video) => {
const { effectiveDate: _effectiveDate, ...videoWithoutEffectiveDate } =
Expand Down
14 changes: 2 additions & 12 deletions apps/web/app/(org)/dashboard/caps/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,7 @@ export default async function CapsPage(props: PageProps<"/dashboard/caps">) {
)
`,
ownerName: users.name,
effectiveDate: sql<string>`
COALESCE(
JSON_UNQUOTE(JSON_EXTRACT(${videos.metadata}, '$.customCreatedAt')),
${videos.createdAt}
)
`,
effectiveDate: videos.effectiveCreatedAt,
hasPassword: sql`${videos.password} IS NOT NULL`.mapWith(Boolean),
hasActiveUpload: sql`${videoUploads.videoId} IS NOT NULL`.mapWith(
Boolean,
Expand Down Expand Up @@ -198,12 +193,7 @@ export default async function CapsPage(props: PageProps<"/dashboard/caps">) {
videos.orgId,
users.name,
)
.orderBy(
desc(sql`COALESCE(
JSON_UNQUOTE(JSON_EXTRACT(${videos.metadata}, '$.customCreatedAt')),
${videos.createdAt}
)`),
)
.orderBy(desc(videos.effectiveCreatedAt))
.limit(limit)
.offset(offset);

Expand Down
16 changes: 4 additions & 12 deletions apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export default async function SharedCapsPage(props: {
totalComments: sql<number>`COUNT(DISTINCT CASE WHEN ${comments.type} = 'text' THEN ${comments.id} END)`,
totalReactions: sql<number>`COUNT(DISTINCT CASE WHEN ${comments.type} = 'emoji' THEN ${comments.id} END)`,
ownerName: users.name,
effectiveDate: sql<string>`COALESCE(JSON_UNQUOTE(JSON_EXTRACT(${videos.metadata}, '$.customCreatedAt')), ${videos.createdAt})`,
effectiveDate: videos.effectiveCreatedAt,
hasActiveUpload: sql`${videoUploads.videoId} IS NOT NULL`.mapWith(
Boolean,
),
Expand All @@ -218,11 +218,7 @@ export default async function SharedCapsPage(props: {
videos.metadata,
users.name,
)
.orderBy(
desc(
sql`COALESCE(JSON_UNQUOTE(JSON_EXTRACT(${videos.metadata}, '$.customCreatedAt')), ${videos.createdAt})`,
),
)
.orderBy(desc(videos.effectiveCreatedAt))
.limit(limit)
.offset(offset),
db()
Expand Down Expand Up @@ -292,7 +288,7 @@ export default async function SharedCapsPage(props: {
totalComments: sql<number>`COUNT(DISTINCT CASE WHEN ${comments.type} = 'text' THEN ${comments.id} END)`,
totalReactions: sql<number>`COUNT(DISTINCT CASE WHEN ${comments.type} = 'emoji' THEN ${comments.id} END)`,
ownerName: users.name,
effectiveDate: sql<string>`COALESCE(JSON_UNQUOTE(JSON_EXTRACT(${videos.metadata}, '$.customCreatedAt')), ${videos.createdAt})`,
effectiveDate: videos.effectiveCreatedAt,
hasActiveUpload: sql`${videoUploads.videoId} IS NOT NULL`.mapWith(
Boolean,
),
Expand All @@ -317,11 +313,7 @@ export default async function SharedCapsPage(props: {
users.name,
videos.duration,
)
.orderBy(
desc(
sql`COALESCE(JSON_UNQUOTE(JSON_EXTRACT(${videos.metadata}, '$.customCreatedAt')), ${videos.createdAt})`,
),
)
.orderBy(desc(videos.effectiveCreatedAt))
.limit(limit)
.offset(offset),
db()
Expand Down
14 changes: 2 additions & 12 deletions apps/web/lib/folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,7 @@ export const getVideosByFolderId = Effect.fn(function* (
`,

ownerName: users.name,
effectiveDate: sql<string>`
COALESCE(
JSON_UNQUOTE(JSON_EXTRACT(${videos.metadata}, '$.customCreatedAt')),
${videos.createdAt}
)
`,
effectiveDate: videos.effectiveCreatedAt,
hasPassword: sql`${videos.password} IS NOT NULL`.mapWith(Boolean),
hasActiveUpload: sql`${videoUploads.videoId} IS NOT NULL`.mapWith(
Boolean,
Expand Down Expand Up @@ -240,12 +235,7 @@ export const getVideosByFolderId = Effect.fn(function* (
videos.metadata,
users.name,
)
.orderBy(
desc(sql`COALESCE(
JSON_UNQUOTE(JSON_EXTRACT(${videos.metadata}, '$.customCreatedAt')),
${videos.createdAt}
)`),
),
.orderBy(desc(videos.effectiveCreatedAt)),
);

// Fetch shared spaces data for all videos
Expand Down
21 changes: 21 additions & 0 deletions packages/database/migrations/0007_public_toxin.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ALTER TABLE `accounts` DROP INDEX `accounts_id_unique`;--> statement-breakpoint
ALTER TABLE `folders` DROP INDEX `folders_id_unique`;--> statement-breakpoint
ALTER TABLE `organization_invites` DROP INDEX `organization_invites_id_unique`;--> statement-breakpoint
ALTER TABLE `organization_members` DROP INDEX `organization_members_id_unique`;--> statement-breakpoint
ALTER TABLE `organizations` DROP INDEX `organizations_id_unique`;--> statement-breakpoint
ALTER TABLE `sessions` DROP INDEX `sessions_id_unique`;--> statement-breakpoint
ALTER TABLE `sessions` DROP INDEX `sessions_sessionToken_unique`;--> statement-breakpoint
ALTER TABLE `users` DROP INDEX `users_id_unique`;--> statement-breakpoint
ALTER TABLE `users` DROP INDEX `users_email_unique`;--> statement-breakpoint
ALTER TABLE `videos` DROP INDEX `videos_id_unique`;--> statement-breakpoint
DROP INDEX `user_id_idx` ON `organization_members`;--> statement-breakpoint
DROP INDEX `owner_id_idx` ON `organizations`;--> statement-breakpoint
DROP INDEX `id_idx` ON `videos`;--> statement-breakpoint
ALTER TABLE `videos` ADD `effectiveCreatedAt` datetime GENERATED ALWAYS AS (COALESCE(
STR_TO_DATE(JSON_UNQUOTE(JSON_EXTRACT(`metadata`, '$.customCreatedAt')), '%Y-%m-%dT%H:%i:%s.%fZ'),
STR_TO_DATE(JSON_UNQUOTE(JSON_EXTRACT(`metadata`, '$.customCreatedAt')), '%Y-%m-%dT%H:%i:%sZ'),
`createdAt`
)) STORED;--> statement-breakpoint
CREATE INDEX `owner_id_tombstone_idx` ON `organizations` (`ownerId`,`tombstoneAt`);--> statement-breakpoint
CREATE INDEX `org_owner_folder_idx` ON `videos` (`orgId`,`ownerId`,`folderId`);--> statement-breakpoint
CREATE INDEX `org_effective_created_idx` ON `videos` (`orgId`,`effectiveCreatedAt`);
16 changes: 16 additions & 0 deletions packages/database/migrations/0008_fat_ender_wiggin.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ALTER TABLE `auth_api_keys` DROP INDEX `auth_api_keys_id_unique`;--> statement-breakpoint
ALTER TABLE `comments` DROP INDEX `comments_id_unique`;--> statement-breakpoint
ALTER TABLE `notifications` DROP INDEX `notifications_id_unique`;--> statement-breakpoint
ALTER TABLE `s3_buckets` DROP INDEX `s3_buckets_id_unique`;--> statement-breakpoint
ALTER TABLE `shared_videos` DROP INDEX `shared_videos_id_unique`;--> statement-breakpoint
ALTER TABLE `space_members` DROP INDEX `space_members_id_unique`;--> statement-breakpoint
ALTER TABLE `space_videos` DROP INDEX `space_videos_id_unique`;--> statement-breakpoint
ALTER TABLE `spaces` DROP INDEX `spaces_id_unique`;--> statement-breakpoint
DROP INDEX `video_id_idx` ON `comments`;--> statement-breakpoint
DROP INDEX `recipient_id_idx` ON `notifications`;--> statement-breakpoint
DROP INDEX `video_id_idx` ON `shared_videos`;--> statement-breakpoint
DROP INDEX `space_id_idx` ON `space_members`;--> statement-breakpoint
DROP INDEX `space_id_user_id_idx` ON `space_members`;--> statement-breakpoint
DROP INDEX `space_id_idx` ON `space_videos`;--> statement-breakpoint
CREATE INDEX `video_type_created_idx` ON `comments` (`videoId`,`type`,`createdAt`,`id`);--> statement-breakpoint
CREATE INDEX `space_id_folder_id_idx` ON `space_videos` (`spaceId`,`folderId`);
31 changes: 31 additions & 0 deletions packages/database/migrations/0008_secondary_index_cleanup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
ALTER TABLE `shared_videos`
DROP INDEX `shared_videos_id_unique`,
DROP INDEX `video_id_idx`;

ALTER TABLE `comments`
DROP INDEX `comments_id_unique`,
DROP INDEX `video_id_idx`,
ADD INDEX `video_type_created_idx` (`videoId`, `type`, `createdAt`, `id`);

ALTER TABLE `notifications`
DROP INDEX `notifications_id_unique`,
DROP INDEX `recipient_id_idx`;

ALTER TABLE `s3_buckets`
DROP INDEX `s3_buckets_id_unique`;

ALTER TABLE `auth_api_keys`
DROP INDEX `auth_api_keys_id_unique`;

ALTER TABLE `spaces`
DROP INDEX `spaces_id_unique`;

ALTER TABLE `space_members`
DROP INDEX `space_members_id_unique`,
DROP INDEX `space_id_idx`,
DROP INDEX `space_id_user_id_idx`;

ALTER TABLE `space_videos`
DROP INDEX `space_videos_id_unique`,
DROP INDEX `space_id_idx`,
ADD INDEX `space_id_folder_id_idx` (`spaceId`, `folderId`);
Loading
Loading