| 204 | } |
| 205 | |
| 206 | async function readAndProcessEvents() { |
| 207 | console.log('Reading events from:', RAW_FILE); |
| 208 | |
| 209 | const fileStream = createReadStream(RAW_FILE); |
| 210 | const rl = createInterface({ |
| 211 | input: fileStream, |
| 212 | crlfDelay: Infinity, |
| 213 | }); |
| 214 | |
| 215 | let count = 0; |
| 216 | let accumulated = ''; |
| 217 | |
| 218 | for await (const line of rl) { |
| 219 | const trimmed = line.trim(); |
| 220 | if (!trimmed) continue; |
| 221 | |
| 222 | // If line starts with {, it's a new JSON object |
| 223 | if (trimmed.startsWith('{')) { |
| 224 | // Try to parse any accumulated content first |
| 225 | if (accumulated) { |
| 226 | try { |
| 227 | const event = JSON.parse(accumulated) as GitHubEvent; |
| 228 | processEvent(event); |
| 229 | count++; |
| 230 | } catch { |
| 231 | // Skip malformed accumulated content |
| 232 | } |
| 233 | } |
| 234 | accumulated = line; |
| 235 | } else { |
| 236 | // This line is a continuation of previous (embedded newline in JSON string) |
| 237 | // The newline needs to be escaped for JSON.parse to accept it |
| 238 | accumulated += '\\n' + line; |
| 239 | } |
| 240 | |
| 241 | if (count % 100000 === 0 && count > 0) { |
| 242 | console.log(`Processed ${count} events...`); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | // Don't forget the last accumulated entry |
| 247 | if (accumulated) { |
| 248 | try { |
| 249 | const event = JSON.parse(accumulated) as GitHubEvent; |
| 250 | processEvent(event); |
| 251 | count++; |
| 252 | } catch { |
| 253 | // Skip malformed |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | console.log(`\nTotal events processed: ${count}`); |
| 258 | console.log(`Unique repos: ${repos.size}`); |
| 259 | console.log(`Issues: ${issues.size}`); |
| 260 | console.log(`Pull requests: ${pulls.size}`); |
| 261 | console.log(`Users: ${users.size}`); |
| 262 | } |
| 263 | |