import { dbAdapter } from '../../../models'
import { reportError } from '../../../support/exceptions'
import { serializePostsCollection } from '../../../serializers/v2/post';

export default class TimelinesController {
  app = null;

  constructor(app) {
    this.app = app;
  }

  bestOf = async (req, res) => {
    try {
      const DEFAULT_LIMIT = 30;

      const currentUserId = req.user ? req.user.id : null;
      const offset = parseInt(req.query.offset, 10) || 0;
      const limit =  parseInt(req.query.limit, 10) || DEFAULT_LIMIT;

      const foundPosts = await dbAdapter.bestPosts(req.user, offset, limit);
      const postsObjects = dbAdapter.initRawPosts(foundPosts, { currentUser: currentUserId });
      const postsCollectionJson = await serializePostsCollection(postsObjects);

      res.jsonp(postsCollectionJson);
    } catch (e) {
      reportError(res)(e);
    }
  };
}

@@ -1,16 +1,50 @@
+import monitor from 'monitor-dog'%0A
 import %7B dbAdapt
@@ -340,16 +340,74 @@
 s) =%3E %7B%0A
+    const timer = monitor.timer('timelines.bestof-time')%0A%0A
     try 
@@ -919,16 +919,69 @@
 nJson);%0A
+      monitor.increment('timelines.bestof-requests')%0A
     %7D ca
@@ -1017,16 +1017,51 @@
 es)(e);%0A
+    %7D finally %7B%0A      timer.stop()%0A
     %7D%0A  

Add performance monitoring for Best Of