()
| 134 | } |
| 135 | |
| 136 | async function getVideoIds() { |
| 137 | const dbUrl = process.env.DATABASE_URL; |
| 138 | if (!dbUrl) { |
| 139 | throw new Error("DATABASE_URL environment variable is required"); |
| 140 | } |
| 141 | |
| 142 | const config = parseDatabaseUrl(dbUrl); |
| 143 | const connection = await mysql.createConnection(config); |
| 144 | |
| 145 | try { |
| 146 | const [rows] = await connection.execute( |
| 147 | "SELECT id, orgId FROM videos LIMIT 1000", |
| 148 | ); |
| 149 | |
| 150 | const videoIds = rows.map((r) => r.id); |
| 151 | const orgMap = new Map(); |
| 152 | for (const row of rows) { |
| 153 | orgMap.set(row.id, row.orgId || ""); |
| 154 | } |
| 155 | |
| 156 | return { videoIds, orgMap }; |
| 157 | } finally { |
| 158 | await connection.end(); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | function distributeViews(videoIds, totalViews) { |
| 163 | if (videoIds.length === 0) return []; |
no test coverage detected