|
@@ -9,7 +9,7 @@ const snowflake = (epoch) => Number.isNaN(epoch) ? undefined :
|
|
|
utils_1.BigNumOps.lShift(String(epoch - 1 - TWITTER_EPOCH), 22);
|
|
|
exports.snowflake = snowflake;
|
|
|
const logger = loggers_1.getLogger('twitter');
|
|
|
-let queryByRegExp = (username, regexp, cacheSeconds, until) => Promise.resolve(null);
|
|
|
+let queryByRegExp = (username, regexp, queryThreshold, until) => Promise.resolve(null);
|
|
|
exports.queryByRegExp = queryByRegExp;
|
|
|
class default_1 {
|
|
|
constructor(opt) {
|
|
@@ -69,14 +69,14 @@ class default_1 {
|
|
|
access_token_key: opt.accessTokenKey,
|
|
|
access_token_secret: opt.accessTokenSecret,
|
|
|
});
|
|
|
- exports.queryByRegExp = (username, regexp, cacheSeconds, until) => {
|
|
|
+ exports.queryByRegExp = (username, regexp, queryThreshold, until) => {
|
|
|
logger.info(`searching timeline of @${username} for matches of ${regexp}...`);
|
|
|
const normalizedUsername = username.toLowerCase().replace(/^@/, '');
|
|
|
const queryKey = `${normalizedUsername}:${regexp.toString()}`;
|
|
|
- const isOld = (then) => {
|
|
|
+ const isOld = (then, threshold = 360) => {
|
|
|
if (!then)
|
|
|
return true;
|
|
|
- return utils_1.BigNumOps.compare(exports.snowflake(Date.now() - cacheSeconds * 1000), then) >= 0;
|
|
|
+ return utils_1.BigNumOps.compare(exports.snowflake(Date.now() - threshold * 1000), then) >= 0;
|
|
|
};
|
|
|
if (queryKey in this.lastQueries && !isOld(this.lastQueries[queryKey].id)) {
|
|
|
const { match, id } = this.lastQueries[queryKey];
|
|
@@ -93,9 +93,9 @@ class default_1 {
|
|
|
return match;
|
|
|
}
|
|
|
const last = tweets.slice(-1)[0].id_str;
|
|
|
- if (isOld(last))
|
|
|
+ if (isOld(last, queryThreshold))
|
|
|
return null;
|
|
|
- exports.queryByRegExp(username, regexp, cacheSeconds, last);
|
|
|
+ return exports.queryByRegExp(username, regexp, queryThreshold, last);
|
|
|
});
|
|
|
};
|
|
|
}
|