Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const bodyParser = require('body-parser')
const { errors } = require('celebrate')
const path = require('path')
const helmet = require('helmet')
const sslRedirect = require('heroku-ssl-redirect')
// const sslRedirect = require('heroku-ssl-redirect')

/** Create Express application */
const app = express()
Expand Down Expand Up @@ -76,19 +76,27 @@ const migrations = require('./migrations/index')
const throng = require('./misc/throng')

const memoryUsage = () => {
const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024 * 100) / 100} MB`
const formatMemoryUsage = data =>
`${Math.round((data / 1024 / 1024) * 100) / 100} MB`

const memoryData = process.memoryUsage()

const memoryUsage = {
rss: `${formatMemoryUsage(memoryData.rss)} -> Resident Set Size - total memory allocated for the process execution`,
heapTotal: `${formatMemoryUsage(memoryData.heapTotal)} -> total size of the allocated heap`,
heapUsed: `${formatMemoryUsage(memoryData.heapUsed)} -> actual memory used during the execution`,
external: `${formatMemoryUsage(memoryData.external)} -> V8 external memory`,
rss: `${formatMemoryUsage(
memoryData.rss,
)} -> Resident Set Size - total memory allocated for the process execution`,
heapTotal: `${formatMemoryUsage(
memoryData.heapTotal,
)} -> total size of the allocated heap`,
heapUsed: `${formatMemoryUsage(
memoryData.heapUsed,
)} -> actual memory used during the execution`,
external: `${formatMemoryUsage(
memoryData.external,
)} -> V8 external memory`,
}

console.log(memoryUsage)

}

throng({
Expand All @@ -109,21 +117,15 @@ throng({

httpServer.listen(PORT, () => {
logger.info(
`Worker ${process.pid} started, listening on port ${httpServer.address().port}`,

`Worker ${process.pid} started, listening on port ${
httpServer.address().port
}`,
)

})

memoryUsage()




},



/** This is run only if the master function errors out, which means the
* server could not start properly. Workers are automatically revived on failure, if e.g.
* the app crashes or runs out of memory while processing a request.
Expand All @@ -138,4 +140,4 @@ throng({
})
process.exit(1)
},
})
})
34 changes: 15 additions & 19 deletions backend/modules/alert/graphql.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { withFilter } = require('graphql-subscriptions')
const { RedisPubSub } = require('graphql-redis-subscriptions')
// const { RedisPubSub } = require('graphql-redis-subscriptions')
const {
GraphQLString,
GraphQLObjectType,
Expand All @@ -11,16 +11,12 @@ const {
const { GraphQLDate } = require('graphql-iso-date')
const RegistrationController = require('../registration/controller')
const Event = require('../event/model')
const Redis = require('ioredis')
//const client = new Redis("rediss://default:JSVhlHFiXTnFo1Z1IVok05TOQqccA2qB@redis-11912.c226.eu-west-1-3.ec2.cloud.redislabs.com:11912");
//console.log(client,"##")


const pubsub = new RedisPubSub({
publisher: new Redis(process.env.REDISCLOUD_URL),
subscriber: new Redis(process.env.REDISCLOUD_URL)
})
// const Redis = require('ioredis')

// const pubsub = new RedisPubSub({
// publisher: new Redis(process.env.REDISCLOUD_URL),
// subscriber: new Redis(process.env.REDISCLOUD_URL),
// })

const AlertInput = new GraphQLInputObjectType({
name: 'AlertInput',
Expand Down Expand Up @@ -120,13 +116,13 @@ const Resolvers = {
throw new Error('You are not an organiser of this event')
}

pubsub.publish('ALERT_SENT', {
newAlert: {
...args.alert,
sentAt: new Date(),
sender: userId,
},
})
// pubsub.publish('ALERT_SENT', {
// newAlert: {
// ...args.alert,
// sentAt: new Date(),
// sender: userId,
// },
// })

return context.controller('Alert').send(args.alert, userId)
},
Expand All @@ -135,9 +131,9 @@ const Resolvers = {
newAlert: {
subscribe: withFilter(
() => {
return pubsub.asyncIterator('ALERT_SENT')
// return pubsub.asyncIterator('ALERT_SENT')
},
async ({newAlert}, { eventId, slug }, { user }) => {
async ({ newAlert }, { eventId, slug }, { user }) => {
// Check authentication from context
const userId = user ? user.sub : null
if (!userId) {
Expand Down
11 changes: 10 additions & 1 deletion backend/modules/event/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,10 @@ const EventSchema = new mongoose.Schema({
type: [EventPageScriptSchema.mongoose],
default: [],
},
meetingsEnabled: false,
meetingsEnabled: {
type: Boolean,
default: false,
},
meetingRooms: {
type: [MeetingRoomSchema.mongoose],
default: [],
Expand All @@ -426,6 +429,12 @@ const EventSchema = new mongoose.Schema({
//New fields for score criteria and score settings
scoreCriteriaSettings: {
type: ScoreCriteriaSettingsSchema.mongoose,
default: {
scoreCriteria: [{criteria: 'overall', label: 'Overall'}],
showScore: false,
showFeedback: false,
reviewAnyChallenge: false,
},
},
experimental: {
type: Boolean,
Expand Down
29 changes: 14 additions & 15 deletions backend/modules/message/graphql.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { GraphQLBoolean } = require('graphql')
const { withFilter } = require('graphql-subscriptions')
const { RedisPubSub } = require('graphql-redis-subscriptions')
// const { RedisPubSub } = require('graphql-redis-subscriptions')
const {
GraphQLString,
GraphQLObjectType,
Expand All @@ -10,13 +10,12 @@ const {
GraphQLInputObjectType,
} = require('graphql')
const { GraphQLDate } = require('graphql-iso-date')
const Redis = require('ioredis')
// const Redis = require('ioredis')


const pubsub = new RedisPubSub({
publisher: new Redis(process.env.REDISCLOUD_URL),
subscriber: new Redis(process.env.REDISCLOUD_URL)
})
// const pubsub = new RedisPubSub({
// publisher: new Redis(process.env.REDISCLOUD_URL),
// subscriber: new Redis(process.env.REDISCLOUD_URL)
// })
const MessageInput = new GraphQLInputObjectType({
name: 'MessageInput',
fields: {
Expand Down Expand Up @@ -119,13 +118,13 @@ const Resolvers = {
const userId = context.req.user ? context.req.user.sub : null
if (!userId) return null

pubsub.publish('MESSAGE_SENT', {
newMessage: {
...args.message,
sentAt: new Date(),
sender: userId,
},
})
// pubsub.publish('MESSAGE_SENT', {
// newMessage: {
// ...args.message,
// sentAt: new Date(),
// sender: userId,
// },
// })

return context.controller('Message').send(args.message, userId)
},
Expand All @@ -146,7 +145,7 @@ const Resolvers = {
newMessage: {
subscribe: withFilter(
() => {
return pubsub.asyncIterator('MESSAGE_SENT')
// return pubsub.asyncIterator('MESSAGE_SENT')
},
({ newMessage }, _, { user }) => {
// Check authentication from context
Expand Down
23 changes: 10 additions & 13 deletions backend/modules/registration/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,26 +522,20 @@ controller.rejectSoftRejected = async eventId => {
return rejected
}

// TODO optimize how gavelData and registrations are matched to avoid O(n^2) complexity
controller.addGavelLoginToRegistrations = async (eventId, gavelData) => {
console.log('Gavel data received', gavelData, typeof gavelData)
let updateCount = 0
const registrations = await Registration.find({
event: eventId,
status: RegistrationStatuses.asObject.checkedIn.id,
})
gavelData.forEach(gavel => {
if (
typeof gavel.registration !== 'string' ||
typeof gavel.link !== 'string'
) {
throw new Error('Gavel data is invalid')
}
})
let updateCount = 0
const registrations = await Registration.find({
event: eventId,
status: RegistrationStatuses.asObject.checkedIn.id,
})
console.log('Registrations found', registrations.length)
console.log('Registrations data', registrations)
const registrationCount = registrations.length

gavelData.forEach(gavel => {
const registration = registrations.find(
r => r._id.toString() === gavel.registration,
)
Expand All @@ -552,7 +546,10 @@ controller.addGavelLoginToRegistrations = async (eventId, gavelData) => {
registration.save()
}
})

console.log('Registrations found', registrations.length)
console.log('Registrations data', registrations)
const registrationCount = registrations.length

console.log(
'Modified counts, updated/total',
updateCount,
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/components/layouts/MaterialTabsLayout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export default ({ tabs, location, baseRoute, transparent = false }) => {

const pushRoute = useCallback(
path => {
console.log("pushing", `${baseRoute}${path}`)
dispatch(push(`${baseRoute}${path}`))
},
[baseRoute, dispatch],
Expand All @@ -69,15 +68,12 @@ export default ({ tabs, location, baseRoute, transparent = false }) => {

const activeIndex = useMemo(() => {
const relativePath = location.pathname.replace(baseRoute, '')
console.log("relativePath matTab", relativePath)
const idx = findIndex(tabs, item => item.path === relativePath)
console.log("safeIndex matTab", idx, idx !== -1)
return idx
}, [baseRoute, location.pathname, tabs])

useEffect(() => {
if (activeIndex === -1) {
console.log("pushRoute(tabs[0].path)", pushRoute(tabs[0].path))
pushRoute(tabs[0].path)
}
}, [tabs, activeIndex, pushRoute])
Expand Down
31 changes: 0 additions & 31 deletions frontend/src/components/layouts/SidebarLayout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export default React.memo(
}) => {
const dispatch = useDispatch()
const routes = _routes.filter(route => !route.hidden)
console.log("ROUTES", routes)

const activeIndex = useMemo(() => {
const relativePath = location.pathname.replace(baseRoute, '')
Expand All @@ -141,21 +140,16 @@ export default React.memo(
return relativePath.indexOf(item.path) !== -1
}
})
console.log("INDEX", idx)
console.log(relativePath)
if (idx === -1) {
switch (relativePath) {
case '/events':
idx = routes.length
console.log('/events', idx)
break
case '/events/organize':
idx = routes.length
console.log('/events', idx)
break
case '/events/partner':
idx = routes.length
console.log('/events', idx)
break
case '/profile':
idx = routes.length + 1
Expand All @@ -166,21 +160,18 @@ export default React.memo(
default: idx = -1
}
}
console.log("IDX", idx)
return idx
}, [baseRoute, location.pathname, routes])

const pushRoute = useCallback(
path => {
console.log(`push(${baseRoute}${path})`)
dispatch(push(`${baseRoute}${path}`))
},
[baseRoute, dispatch],
)

useEffect(() => {
if (activeIndex === -1) {
console.log("PUSHING ", routes, "activeIndex", activeIndex)
//pushRoute(routes[0].path)
}
}, [routes, activeIndex, pushRoute])
Expand Down Expand Up @@ -271,7 +262,6 @@ export default React.memo(
selected: classes.listItemSelected,
}}
onClick={() => {
console.log("safeIndex", safeIndex)
pushRoute('/events')
}}
>
Expand Down Expand Up @@ -340,11 +330,6 @@ export default React.memo(
primary={'Log Out'}
/>
</ListItem>
<ListItem>
{/*TODO: language menu */}
{/* <img src={FlagUK} width="40" height="30" ></img> */}

</ListItem>
</div>
</List>
</>
Expand Down Expand Up @@ -426,24 +411,8 @@ export default React.memo(
},
index,
) => {
// console.log("PROPS: ", "key", key,
// "path", `${baseRoute}${path}`,
// "hidden", hidden,
// "component", component,
// exact = false,
// "locked", locked,
// "index", index)
if (hidden || locked) {
return null
// } else if (index === 5) {
// console.log("ROUTING EVENT_ID")
// return (< Route
// key={'eventId2'}
// exact={false}
// path={`${baseRoute}/event-id`
// }
// component={LogoutPage}
// />)

} else {
return (
Expand Down
Loading