| 95 | >; |
| 96 | |
| 97 | export class Videos extends Effect.Service<Videos>()("Videos", { |
| 98 | effect: Effect.gen(function* () { |
| 99 | const db = yield* Database; |
| 100 | const repo = yield* VideosRepo; |
| 101 | const policy = yield* VideosPolicy; |
| 102 | const storage = yield* StorageService; |
| 103 | const tinybird = yield* Tinybird; |
| 104 | |
| 105 | const getByIdForViewing = (id: Video.VideoId) => |
| 106 | repo |
| 107 | .getById(id) |
| 108 | .pipe( |
| 109 | Policy.withPublicPolicy(policy.canView(id)), |
| 110 | Effect.withSpan("Videos.getById"), |
| 111 | ); |
| 112 | |
| 113 | const getAnalyticsBulkInternal = Effect.fn("Videos.getAnalyticsBulk")( |
| 114 | function* (videoIds: ReadonlyArray<Video.VideoId>) { |
| 115 | if (videoIds.length === 0) |
| 116 | return [] as Array<Exit.Exit<{ count: number }, unknown>>; |
| 117 | |
| 118 | const now = new Date(); |
| 119 | const from = new Date( |
| 120 | now.getTime() - DEFAULT_ANALYTICS_RANGE_DAYS * 24 * 60 * 60 * 1000, |
| 121 | ); |
| 122 | |
| 123 | const videoExits = yield* Effect.forEach( |
| 124 | videoIds, |
| 125 | (videoId) => |
| 126 | getByIdForViewing(videoId).pipe( |
| 127 | Effect.map((video) => video), |
| 128 | Effect.exit, |
| 129 | ), |
| 130 | { concurrency: 10 }, |
| 131 | ); |
| 132 | |
| 133 | const successfulVideos: Array<{ |
| 134 | index: number; |
| 135 | videoId: Video.VideoId; |
| 136 | video: Video.Video; |
| 137 | }> = []; |
| 138 | |
| 139 | for (let index = 0; index < videoExits.length; index++) { |
| 140 | const exit = videoExits[index]; |
| 141 | if (!exit) continue; |
| 142 | if (Exit.isSuccess(exit)) { |
| 143 | const maybeVideo = exit.value; |
| 144 | if (Option.isSome(maybeVideo)) { |
| 145 | const [video] = maybeVideo.value; |
| 146 | successfulVideos.push({ |
| 147 | index, |
| 148 | videoId: videoIds[index] ?? "", |
| 149 | video, |
| 150 | }); |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 |
nothing calls this directly
no test coverage detected