Skip to content

Commit

Permalink
Merge #3105
Browse files Browse the repository at this point in the history
3105: chore: remove Topic r=jniles a=jniles

The Topic library is an event emitter with no consumers implemented.  At our production sites, we do not even write to the database the events. Thus, this commit removes Topic until we have a real use case for it.

It should also improve performances slightly since we will not be Pub/Sub-ing events to Redis.

Closes #3091.

Co-authored-by: Jonathan Niles <jonathanwniles@gmail.com>
  • Loading branch information
bors[bot] and jniles committed Aug 31, 2018
2 parents 9746a45 + a596db9 commit d14d453
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 430 deletions.
39 changes: 3 additions & 36 deletions client/src/js/services/System.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,24 @@
/* global EventSource */
angular.module('bhima.services')
.service('SystemService', SystemService);
.service('SystemService', SystemService);

SystemService.$inject = ['$http', 'util'];

/**
* System Service
*/
function SystemService($http, util) {
var service = this;
var baseUrl = '/system';
const service = this;
const baseUrl = '/system';

// exposed API
service.information = information;
service.events = events;
service.stream = [];

function information() {
return $http.get(baseUrl.concat('/information'))
.then(util.unwrapHttpResponse);
}

function events() {
// forcibly clear the event queue
service.stream.length = 0;

return $http.get(baseUrl.concat('/events'))
.then(util.unwrapHttpResponse);
}

function handleServerSentEvent(event) {
console.log('Got Event:', event);
service.stream.push(JSON.parse(event.data));
}

function handleErrorEvent(event) {
if (event.readyState === EventSource.CLOSED) {
console.log('Connection was closed.');
}
}

function handleOpenEvent(event) {
console.log('Connection was open.');
}

/*
// set up event stream
var source = new EventSource(baseUrl.concat('/stream'));
source.addEventListener('open', handleOpenEvent, false);
source.addEventListener('message', handleServerSentEvent, false);
source.addEventListener('error', handleErrorEvent, false);
*/

return service;
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"jeremielodi"
],
"dependencies": {
"@ima-worldhealth/topic": "^1.0.1",
"@types/angular": "^1.6.41",
"accounting-js": "^1.1.1",
"body-parser": "^1.15.0",
Expand Down
2 changes: 0 additions & 2 deletions server/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ exports.configure = function configure(app) {
app.post('/auth/reload', auth.reload);

// system and event helpers
app.get('/system/events', system.events);
app.get('/system/stream', system.stream);
app.get('/system/information', system.info);

// dashbord stats
Expand Down
30 changes: 0 additions & 30 deletions server/controllers/admin/locations.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@


const uuid = require('uuid/v4');
const Topic = require('@ima-worldhealth/topic');

const db = require('../../lib/db');

exports.lookupVillage = lookupVillage;
Expand Down Expand Up @@ -310,13 +308,6 @@ exports.create.country = function createCountry(req, res, next) {

db.exec(sql, [db.bid(req.body.uuid), req.body.name])
.then(() => {
Topic.publish(Topic.channels.ADMIN, {
event : Topic.events.CREATE,
entity : Topic.entities.LOCATION,
user_id : req.session.user.id,
uuid : req.body.uuid,
});

res.status(201).json({ uuid : req.body.uuid });
})
.catch(next)
Expand Down Expand Up @@ -345,13 +336,6 @@ exports.create.province = function createProvince(req, res, next) {

db.exec(sql, [[db.bid(data.uuid), data.name, data.country_uuid]])
.then(() => {
Topic.publish(Topic.channels.ADMIN, {
event : Topic.events.CREATE,
entity : Topic.entities.LOCATION,
user_id : req.session.user.id,
uuid : data.uuid,
});

res.status(201).json({ uuid : data.uuid });
})
.catch(next)
Expand Down Expand Up @@ -379,13 +363,6 @@ exports.create.sector = function createSector(req, res, next) {

db.exec(sql, [[db.bid(data.uuid), data.name, data.province_uuid]])
.then(() => {
Topic.publish(Topic.channels.ADMIN, {
event : Topic.events.CREATE,
entity : Topic.entities.LOCATION,
user_id : req.session.user.id,
uuid : data.uuid,
});

res.status(201).json({ uuid : data.uuid });
})
.catch(next)
Expand All @@ -412,13 +389,6 @@ exports.create.village = function createVillage(req, res, next) {

db.exec(sql, [[db.bid(data.uuid), data.name, data.sector_uuid, data.longitude, data.latitude]])
.then(() => {
Topic.publish(Topic.channels.ADMIN, {
event : Topic.events.CREATE,
entity : Topic.entities.LOCATION,
user_id : req.session.user.id,
uuid : data.uuid,
});

res.status(201).json({ uuid : data.uuid });
})
.catch(next)
Expand Down
23 changes: 0 additions & 23 deletions server/controllers/admin/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
* @requires db
* @requires NotFound
* @requires BadRequest
* @requires Topic
*/


const uuid = require('uuid/v4');
const Topic = require('@ima-worldhealth/topic');

const db = require('../../lib/db');
const NotFound = require('../../lib/errors/NotFound');
Expand Down Expand Up @@ -72,13 +70,6 @@ function create(req, res, next) {

db.exec(sql, [record])
.then((result) => {
Topic.publish(Topic.channels.ADMIN, {
event : Topic.events.CREATE,
entity : Topic.entities.SERVICE,
user_id : req.session.user.id,
id : result.insertId,
});

res.status(201).json({ id : result.insertId });
})
.catch(next)
Expand Down Expand Up @@ -115,13 +106,6 @@ function update(req, res, next) {
return lookupService(req.params.id);
})
.then((service) => {
Topic.publish(Topic.channels.ADMIN, {
event : Topic.events.UPDATE,
entity : Topic.entities.SERVICE,
user_id : req.session.user.id,
id : req.params.id,
});

res.status(200).json(service);
})
.catch(next)
Expand All @@ -143,13 +127,6 @@ function remove(req, res, next) {
throw new NotFound(`Could not find a service with id ${req.params.id}.`);
}

Topic.publish(Topic.channels.ADMIN, {
event : Topic.events.DELETE,
entity : Topic.entities.SERVICE,
user_id : req.session.user.id,
id : req.params.id,
});

res.sendStatus(204);
})
.catch(next)
Expand Down
13 changes: 0 additions & 13 deletions server/controllers/admin/suppliers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

const uuid = require('uuid/v4');
const Topic = require('@ima-worldhealth/topic');

const db = require('../../lib/db');

Expand Down Expand Up @@ -106,12 +105,6 @@ function create(req, res, next) {

transaction.execute()
.then(() => {
Topic.publish(Topic.channels.INVENTORY, {
event : Topic.events.CREATE,
entity : Topic.entities.SUPPLIER,
user_id : req.session.user.id,
uuid : recordUuid,
});
res.status(201).json({ uuid : recordUuid });
})
.catch(next)
Expand Down Expand Up @@ -156,12 +149,6 @@ function update(req, res, next) {

transaction.execute()
.then(() => {
Topic.publish(Topic.channels.INVENTORY, {
event : Topic.events.UPDATE,
entity : Topic.entities.SUPPLIER,
user_id : req.session.user.id,
uuid : req.params.uuid,
});
return lookupSupplier(req.params.uuid);
})
.then(record => {
Expand Down
22 changes: 0 additions & 22 deletions server/controllers/admin/users/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


const _ = require('lodash');
const Topic = require('@ima-worldhealth/topic');
const db = require('../../../lib/db');
const NotFound = require('../../../lib/errors/NotFound');
const BadRequest = require('../../../lib/errors/BadRequest');
Expand Down Expand Up @@ -174,13 +173,6 @@ function create(req, res, next) {
return db.exec(sql, [projects]);
})
.then(() => {
Topic.publish(Topic.channels.ADMIN, {
event : Topic.events.CREATE,
entity : Topic.entities.USER,
user_id : req.session.user.id,
id : userId,
});

// send the ID back to the client
res.status(201).json({ id : userId });
})
Expand Down Expand Up @@ -248,13 +240,6 @@ function update(req, res, next) {
transaction.execute()
.then(() => lookupUser(req.params.id))
.then((result) => {
Topic.publish(Topic.channels.ADMIN, {
event : Topic.events.UPDATE,
entity : Topic.entities.USER,
user_id : req.session.user.id,
id : req.params.id,
});

res.status(200).json(result);
})
.catch(next)
Expand Down Expand Up @@ -302,13 +287,6 @@ function remove(req, res, next) {
throw new NotFound(`Could not find a user with id ${req.params.id}`);
}

Topic.publish(Topic.channels.ADMIN, {
event : Topic.events.DELETE,
entity : Topic.entities.USER,
user_id : req.session.user.id,
id : req.params.id,
});

res.sendStatus(204);
})
.catch(next)
Expand Down
26 changes: 0 additions & 26 deletions server/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*
* @requires lib/db
* @requires q
* @requires @ima-worldhealth/Topic
* @requires lodash
* @requires lib/errors/Unauthorized
* @requires lib/errors/Forbidden
Expand All @@ -19,7 +18,6 @@

const _ = require('lodash');
const q = require('q');
const Topic = require('@ima-worldhealth/topic');
const db = require('../lib/db');
const Unauthorized = require('../lib/errors/Unauthorized');
const InternalServerError = require('../lib/errors/InternalServerError');
Expand Down Expand Up @@ -104,14 +102,6 @@ function login(req, res, next) {
// bind the session variables
_.merge(req.session, session);

// broadcast LOGIN event
Topic.publish(Topic.channels.APP, {
event : Topic.events.LOGIN,
entity : Topic.entities.USER,
user_id : req.session.user.id,
id : session.user.id,
});

// send the session data back to the client
res.status(200).json(session);
})
Expand All @@ -129,14 +119,6 @@ function logout(req, res, next) {

db.exec(sql, [req.session.user.id])
.then(() => {
// broadcast LOGOUT event
Topic.publish(Topic.channels.APP, {
event : Topic.events.LOGOUT,
entity : Topic.entities.USER,
user_id : req.session.user.id,
id : req.session.user.id,
});

// destroy the session
req.session.destroy();
res.sendStatus(200);
Expand Down Expand Up @@ -288,14 +270,6 @@ function reload(req, res, next) {
// bind the session variables
_.merge(req.session, session);

// broadcast LOGIN event
Topic.publish(Topic.channels.APP, {
event : Topic.events.RELOAD,
entity : Topic.entities.USER,
user_id : req.session.user.id,
id : session.user.id,
});

// send the session data back to the client
res.status(200).json(session);
})
Expand Down
10 changes: 0 additions & 10 deletions server/controllers/finance/cash.create.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const uuid = require('uuid/v4');
const _ = require('lodash');
const Topic = require('@ima-worldhealth/topic');

const db = require('../../lib/db');
const BadRequest = require('../../lib/errors/BadRequest');
Expand Down Expand Up @@ -142,16 +141,7 @@ function create(req, res, next) {
transaction.execute()
.then(() => {
res.status(201).json({ uuid : cashUuidString });

Topic.publish(Topic.channels.FINANCE, {
event : Topic.events.CREATE,
entity : Topic.entities.PAYMENT,
user_id : req.session.user.id,
user : req.session.user.display_name,
uuid : cashUuidString,
});
})
.catch(next)
.done();
}

Loading

0 comments on commit d14d453

Please sign in to comment.