Skip to content

Commit

Permalink
chore: disable search indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
ForbesLindesay committed Jul 13, 2020
1 parent 0eb73d6 commit a43303f
Showing 1 changed file with 47 additions and 47 deletions.
94 changes: 47 additions & 47 deletions src/search.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
const algoliasearch = require('algoliasearch');
import * as db from './database';
// const algoliasearch = require('algoliasearch');
// import * as db from './database';

if (process.env.ALGOLIA_APPLICATION_ID && process.env.ALGOLIA_ADMIN_KEY) {
const client = algoliasearch(process.env.ALGOLIA_APPLICATION_ID, process.env.ALGOLIA_ADMIN_KEY);
// if (process.env.ALGOLIA_APPLICATION_ID && process.env.ALGOLIA_ADMIN_KEY) {
// const client = algoliasearch(process.env.ALGOLIA_APPLICATION_ID, process.env.ALGOLIA_ADMIN_KEY);

const index = client.initIndex('messages');
index.setSettings({"attributeForDistinct":"subjectID"});
// const index = client.initIndex('messages');
// index.setSettings({"attributeForDistinct":"subjectID"});

// initially, we load in pages of 60 records, once per minute until we have looked at the most recent 100 records
// we then check every hour to see if there are any new records, loading in pages of 5 until we get to the most
// recent record we've seen.
let perPage = 60;
let latestMessage = '0000-00-00';
let currentRoundLatestMessage = '0000-00-00';
let roundComplete = false;
function processPage(start: number) {
if (roundComplete || start > 100) {
latestMessage = currentRoundLatestMessage;
roundComplete = false;
setTimeout(() => {
perPage = 5;
processPage(0);
}, 60 * 60_000);
return;
}
db.getAllMessagesForSearch(start, perPage).then(messages => {
messages.forEach(message => {
const messageDate = message.date.toISOString().split('T')[0];
// keep track of the newest message we've seen this round
if (messageDate > currentRoundLatestMessage) {
currentRoundLatestMessage = messageDate;
}
// if the message is older than the most recent message, end the round
if (messageDate < latestMessage) {
roundComplete = true;
}
});
index.saveObjects(messages, (err: any) => {
if (err) {
throw err;
}
setTimeout(() => {
processPage(start + perPage);
}, 5 * 60_000);
});
});
}
processPage(0);
}
// // initially, we load in pages of 60 records, once per minute until we have looked at the most recent 100 records
// // we then check every 24 hours to see if there are any new records, loading in pages of 5 until we get to the most
// // recent record we've seen.
// let perPage = 60;
// let latestMessage = '0000-00-00';
// let currentRoundLatestMessage = '0000-00-00';
// let roundComplete = false;
// function processPage(start: number) {
// if (roundComplete || start > 100 || (new Date()).toISOString().split('T')[0] < '') {
// latestMessage = currentRoundLatestMessage;
// roundComplete = false;
// setTimeout(() => {
// perPage = 5;
// processPage(0);
// }, 24 * 60 * 60_000);
// return;
// }
// db.getAllMessagesForSearch(start, perPage).then(messages => {
// messages.forEach(message => {
// const messageDate = message.date.toISOString().split('T')[0];
// // keep track of the newest message we've seen this round
// if (messageDate > currentRoundLatestMessage) {
// currentRoundLatestMessage = messageDate;
// }
// // if the message is older than the most recent message, end the round
// if (messageDate < latestMessage) {
// roundComplete = true;
// }
// });
// index.saveObjects(messages, (err: any) => {
// if (err) {
// throw err;
// }
// setTimeout(() => {
// processPage(start + perPage);
// }, 20 * 60_000);
// });
// });
// }
// processPage(0);
// }

0 comments on commit a43303f

Please sign in to comment.