Skip to content

Commit bdee1ec

Browse files
committed
archive using pg ids
1 parent 10fccbc commit bdee1ec

File tree

6 files changed

+74
-87
lines changed

6 files changed

+74
-87
lines changed

dev/streamArchive.ts

+39-33
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,46 @@ import cassandra from '../store/cassandra';
22
import db from '../store/db';
33
import { doArchiveFromLegacy } from '../store/queries';
44

5+
const stream = db.raw('SELECT match_id from parsed_matches WHERE is_archived IS NULL').stream();
6+
stream.on('data', async (row) => {
7+
await doArchiveFromLegacy(row.match_id.toString());
8+
// console.log(row);
9+
});
10+
511
let i = 0;
6-
cassandra
7-
.stream('select match_id, version from matches', [], {
8-
prepare: true,
9-
autoPage: true,
10-
})
11-
.on('readable', async function () {
12-
// readable is emitted as soon a row is received and parsed
13-
let row;
14-
//@ts-ignore
15-
while ((row = this.read())) {
16-
// process row
17-
i += 1;
18-
console.log(i, row.match_id);
19-
if (row.version) {
20-
await db.raw(
21-
'INSERT INTO parsed_matches(match_id) VALUES(?) ON CONFLICT DO NOTHING',
22-
[row.match_id]
23-
);
24-
await doArchiveFromLegacy(row.match_id.toString());
25-
} else {
26-
await deleteFromStore(row.match_id.toString());
27-
}
28-
}
29-
})
30-
.on('end', function () {
31-
// emitted when all rows have been retrieved and read
32-
console.log('finished');
33-
process.exit(0);
34-
})
35-
.on('error', function (e) {
36-
console.error(e);
37-
process.exit(1);
38-
});
12+
// const stream = cassandra
13+
// .stream('select match_id, version from matches', [], {
14+
// prepare: true,
15+
// autoPage: true,
16+
// })
17+
// .on('readable', async function () {
18+
// // readable is emitted as soon a row is received and parsed
19+
// let row;
20+
// //@ts-ignore
21+
// while ((row = this.read())) {
22+
// // process row
23+
// i += 1;
24+
// console.log(i, row.match_id);
25+
// if (row.version) {
26+
// await db.raw(
27+
// 'INSERT INTO parsed_matches(match_id) VALUES(?) ON CONFLICT DO NOTHING',
28+
// [row.match_id]
29+
// );
30+
// await doArchiveFromLegacy(row.match_id.toString());
31+
// } else {
32+
// await deleteFromStore(row.match_id.toString());
33+
// }
34+
// }
35+
// });
36+
stream.on('end', function () {
37+
// emitted when all rows have been retrieved and read
38+
console.log('finished');
39+
// process.exit(0);
40+
})
41+
stream.on('error', function (e) {
42+
console.error(e);
43+
// process.exit(1);
44+
});
3945

4046
async function deleteFromStore(id: string) {
4147
await Promise.all([

dev/teamElo.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
22
* Computes team Elo ratings by game
33
* */
4-
import JSONStream from 'JSONStream';
54
import db from '../store/db';
65

76
// Keep each team's rating in memory and update
@@ -23,7 +22,6 @@ ORDER BY match_id ASC
2322
`
2423
)
2524
.stream();
26-
stream.pipe(JSONStream.parse());
2725
stream.on('data', (match) => {
2826
// console.log(JSON.stringify(match));
2927
if (!teams[match.team_id1]) {

dev/wordcount.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import JSONStream from 'JSONStream';
21
import db from '../store/db';
32
import {countWords} from '../util/compute';
43
import { mergeObjects } from '../util/utility';
@@ -17,7 +16,6 @@ stream.on('end', () => {
1716
console.log(JSON.stringify(counts));
1817
process.exit(0);
1918
});
20-
stream.pipe(JSONStream.parse());
2119
stream.on('data', (match) => {
2220
mergeObjects(counts, countWords(match, null));
2321
});

global.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ declare module 'steam';
66
declare module 'dota2';
77
declare module 'passport-steam';
88
declare module 'uuid';
9-
declare module 'JSONStream';
109
declare module 'ws';
1110

1211
declare namespace Express {

package-lock.json

+34-48
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@
4545
"http-proxy": "^1.18.1",
4646
"ioredis": "^5.3.2",
4747
"json-bigint": "^0.3.0",
48-
"JSONStream": "^1.3.5",
4948
"knex": "^3.0.1",
5049
"long": "^4.0.0",
5150
"moment": "^2.24.0",
5251
"nock": "^13.0.5",
5352
"passport": "^0.4.1",
5453
"passport-steam": "^1.0.18",
5554
"pg": "^8.11.3",
55+
"pg-query-stream": "^4.5.3",
5656
"protobufjs": "^7.2.5",
5757
"request": "^2.88.2",
5858
"simple-vdf": "^1.1.1",

0 commit comments

Comments
 (0)