Skip to content

Commit

Permalink
feat(hot-tracks): 🧹 remove computation of relative ranking trends (#737)
Browse files Browse the repository at this point in the history
* remove workers and functions that are no longer necessary

* fix(api-tests): `TypeError: Cannot read properties of undefined (reading 'nbP')`
cf https://github.com/openwhyd/openwhyd/actions/runs/6249333238/job/16965745168?pr=737#step:6:185

* 🧹 drop the `track` collection

* drop references to `tracks`, in search engines
  • Loading branch information
adrienjoly committed Sep 21, 2023
1 parent 27da716 commit 1eed523
Show file tree
Hide file tree
Showing 11 changed files with 10 additions and 349 deletions.
1 change: 0 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ function start() {
console.log(`[app] Server running at ${url}`);
});
require('./app/workers/notifEmails.js'); // start digest worker
require('./app/workers/hotSnapshot.js'); // start hot tracks snapshot worker

function closeGracefully(signal) {
console.warn(`[app] ${signal} signal received: closing server...`);
Expand Down
13 changes: 0 additions & 13 deletions app/controllers/admin/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
**/

const mongodb = require('../../models/mongodb.js');
const trackModel = require('../../models/track.js');
const snip = require('../../snip.js');
const FileController = require('./FileController.js');

Expand Down Expand Up @@ -57,18 +56,6 @@ function listMissingUsers(uids, cb) {
}

var fileGenerators = {
refreshTrackCollection: function (p, cb) {
trackModel.refreshTrackCollection(function (r) {
console.log('refreshTrackCollection => ', r || { ok: 'done' });
});
cb('refreshing track collection...');
},
snapshotTrackScores: function (p, cb) {
trackModel.snapshotTrackScores(function (r) {
console.log('snapshotTrackScores => ', r || { ok: 'done' });
});
cb('refreshing track trends...');
},
'listUsersWithoutPosts.html': async function (p, cb) {
const uidList = await fetchUidList();
listMissingUsers(cleanUidList(uidList), function (users) {
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/private/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ function fetchTheirPosts(q, uid, cb) {
function fetchSearchPage(myUid, q, cb) {
fetchResultsPerType({ q: q }, function (resultsPerType) {
followModel.fetchSubscriptionSet(myUid, function (followedUids) {
const types = ['track', 'user', 'playlist'];
const types = ['user', 'playlist'];
const results = {};
(function next() {
if (!types.length) {
Expand Down
16 changes: 0 additions & 16 deletions app/features/hot-tracks.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
// @ts-check

const FIELDS_TO_SUM = {
nbP: true, // number of plays
nbL: true, // number of likes (from lov[] field)
nbR: true, // number of posts/reposts
};

exports.FIELDS_TO_SUM = FIELDS_TO_SUM;

const FIELDS_TO_COPY = {
name: true,
img: true,
score: true,
};

exports.FIELDS_TO_COPY = FIELDS_TO_COPY;

/**
* @param {() => Promise<{pId: string, eId: string}[]>} getTracksByDescendingScore (partial type definition, just to check usage of objArrayToValueArray)
*/
Expand Down
17 changes: 5 additions & 12 deletions app/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const snip = require('../snip.js');
const notif = require('../models/notif.js');
const searchModel = require('../models/search.js');
const activityModel = require('../models/activity.js');
const trackModel = require('../models/track.js');
const notifModel = require('../models/notif.js');

const NB_POSTS = process.appParams?.nbPostsPerNewsfeedPage;
Expand Down Expand Up @@ -202,7 +201,6 @@ async function setPostLove(collection, pId, uId, state, handler) {
const post = await collection.findOne({ _id: ObjectId('' + pId) });
if (post && uId != post.uId) notif[state ? 'love' : 'unlove'](uId, post);
handler?.(post);
if (post) trackModel.updateByEid(post.eId);
if (state)
activityModel.addLikeByPost(post, {
id: uId,
Expand Down Expand Up @@ -319,11 +317,10 @@ exports.rePost = function (pId, repostObj, handler) {
if (repostObj.uId != repostObj.repost.uId) {
notif.repost(repostObj.uId, postObj);
notif.post(postObj);
collection
.updateOne({ _id: ObjectId('' + pId) }, { $inc: { nbR: 1 } })
.then(() => {
trackModel.updateByEid(postObj.eId);
});
collection.updateOne(
{ _id: ObjectId('' + pId) },
{ $inc: { nbR: 1 } },
);
}
const post = await mongodb.collections['post'].findOne({
_id: ObjectId('' + result.insertedId),
Expand Down Expand Up @@ -366,7 +363,6 @@ exports.deletePost = function (pId, uId, handler) {
{ _id: ObjectId('' + postObj.repost.pId) },
{ $inc: { nbR: -1 } },
);
trackModel.updateByEid(postObj.eId);
} else {
handler(new Error('post not found'));
}
Expand All @@ -383,10 +379,7 @@ exports.incrPlayCounter = function (pId, cb) {
}
mongodb.collections['post'].updateOne({ _id }, { $inc: { nbP: 1 } }).then(
async (/*updateRes*/) => {
const post = await new Promise((resolve) =>
exports.fetchPostById(pId, resolve),
);
if (post?.eId) trackModel.updateByEid(post.eId);
await new Promise((resolve) => exports.fetchPostById(pId, resolve));
cb?.({});
},
(err) => cb?.(err) ?? console.trace('incrPlayCounter', err),
Expand Down
22 changes: 1 addition & 21 deletions app/models/searchAlgolia.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
**/

const snip = require('../snip.js');
const mongodb = require('./mongodb.js');
const algoliasearch = require('algoliasearch');

if (process.env['ALGOLIA_APP_ID'] === undefined)
Expand All @@ -19,14 +18,12 @@ const client = algoliasearch(

const INDEX_NAME_BY_TYPE = {
user: 'users',
track: 'tracks',
post: 'posts',
playlist: 'playlists',
};

const INDEX_TYPE_BY_NAME = {
users: 'user',
tracks: 'track',
posts: 'post',
playlists: 'playlist',
};
Expand Down Expand Up @@ -153,23 +150,6 @@ const searchByType = {
// tested http://localhost:8080/search?q=pouet&context=header
// => { q: 'pouet' }
},
track: function (q, cb) {
console.log('[search] search tracks', q);
const options = extractOptions(q);
return searchIndex.search(
'tracks',
q.q,
options,
makeCallbackTranslator('track', function (res) {
(res.hits || []).map(function (h) {
h.eId = h._id;
h._id = mongodb.ObjectId(h.post);
delete h.post;
});
cb(res);
}),
);
},
post: function (q, cb) {
console.log('[search] search posts', q);
const options = extractOptions(q);
Expand Down Expand Up @@ -233,7 +213,7 @@ exports.query = function (q = {}, cb) {
let queue;
if (q._type) queue = [q._type];
else if (q.uId) queue = ['post'];
else queue = ['user', 'track', 'post', 'playlist']; //Object.keys(searchByType);
else queue = ['user', 'post', 'playlist']; //Object.keys(searchByType);
delete q._type;
(function next() {
const type = queue.pop();
Expand Down
Loading

0 comments on commit 1eed523

Please sign in to comment.