Skip to content

Commit

Permalink
add db cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
pyatyispyatil committed Feb 6, 2020
1 parent 3acf878 commit 907653a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const API_TOKEN = config.telegram.token || '';
const PROXY_OPTIONS = config.telegram.proxy || '';

const PREVIEW_RELEASES_COUNT = -10;
const FIRST_UPDATE_RELEASES_COUNT = 20;
const FIRST_UPDATE_RELEASES_COUNT = 5;
const UPDATE_INTERVAL = Math.floor((config.app.updateInterval / 60) * 100) / 100;


Expand Down
15 changes: 15 additions & 0 deletions src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ class DB {
return await this.repos.find({}, {name: 1, owner: 1, watchedUsers: 1, _id: 0}).toArray();
}

async clearReleases() {
return await Promise.all([
this.repos.update(
{ "releases.5": { "$exists": 1 } },
{ "$push": { "releases": { "$each": [], "$slice": -5 } } },
{ "multi": true }
),
this.repos.update(
{ "tags.5": { "$exists": 1 } },
{ "$push": { "tags": { "$each": [], "$slice": -5 } } },
{ "multi": true }
)
]);
}

async updateRepo(owner, name, {releases: newReleases, tags: newTags}) {
const {releases, tags} = await this.repos.findOne({owner, name});

Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const run = async () => {

const updateReleases = async () => {
try {
await db.clearReleases();
const repos = await db.getAllReposNames();
const updates = await getManyVersionsInBunches(repos.map(({owner, name}) => ({owner, name})), 1);

Expand Down

0 comments on commit 907653a

Please sign in to comment.