Skip to content

Commit

Permalink
async bulkindexplayer
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Dec 4, 2023
1 parent 6d86ca0 commit b931f91
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
8 changes: 3 additions & 5 deletions store/queries.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -572,16 +572,15 @@ export async function insertPlayerPromise(db, player, indexPlayer) {
}
);
}
function bulkIndexPlayer(bulkActions, cb) {
export async function bulkIndexPlayer(bulkActions) {
// Bulk call to ElasticSearch
if (bulkActions.length > 0) {
es.bulk(
await es.bulk(
{
body: bulkActions,
index: INDEX,
type: 'player',
},
cb
}
);
}
}
Expand Down Expand Up @@ -1276,7 +1275,6 @@ export default {
upsert,
upsertPromise,
insertPlayerPromise,
bulkIndexPlayer,
insertMatchPromise,
getHeroRankings,
getHeroItemPopularity,
Expand Down
10 changes: 3 additions & 7 deletions svc/counts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import moment from 'moment';
import redis from '../store/redis.mjs';
import db from '../store/db.mjs';
import utility from '../util/utility.mjs';
import queries, { insertPlayerPromise } from '../store/queries.mjs';
import queries, { insertPlayerPromise, bulkIndexPlayer } from '../store/queries.mjs';
import queue from '../store/queue.mjs';
import config from '../config.js';
const { getMatchRankTier, bulkIndexPlayer, upsertPromise } =
const { getMatchRankTier, upsertPromise } =
queries;
const { getAnonymousAccountId, isRadiant, isSignificant } = utility;
function updateHeroRankings(match, cb) {
Expand Down Expand Up @@ -155,11 +155,7 @@ function updateLastPlayed(match, cb) {
);
return acc;
}, []);
bulkIndexPlayer(bulkUpdate, (err) => {
if (err) {
console.log(err);
}
});
bulkIndexPlayer(bulkUpdate);
Promise.all(filteredPlayers.map(player => insertPlayerPromise(
db,
{
Expand Down
9 changes: 2 additions & 7 deletions svc/profiler.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Updates Steam profile data for players periodically
import queries, { insertPlayerPromise } from '../store/queries.mjs';
import queries, { insertPlayerPromise, bulkIndexPlayer } from '../store/queries.mjs';
import db from '../store/db.mjs';
import utility from '../util/utility.mjs';
const { bulkIndexPlayer } = queries;
const { getDataPromise, generateJob, convert64to32 } = utility;

while (true) {
Expand Down Expand Up @@ -35,11 +34,7 @@ while (true) {
);
return acc;
}, []);
bulkIndexPlayer(bulkUpdate, (err) => {
if (err) {
console.log(err);
}
});
await bulkIndexPlayer(bulkUpdate);
await Promise.all(
results.map((player) => insertPlayerPromise(db, player, false))
);
Expand Down

0 comments on commit b931f91

Please sign in to comment.