This repository has been archived by the owner on Jun 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Update Statistics To Realtime w/ Caching #194
Open
ASankaran
wants to merge
27
commits into
staging
Choose a base branch
from
add-stats
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
f58d8ec
add stats
vsui 68891bc
Merge branch 'master' into add-stats
ASankaran c3cc662
Fixed broken rsvp test
ASankaran 90725d6
Add method to check if stat exists in database
ASankaran 16489ae
Fixed stat increment and update stats on attendee registration
ASankaran c8eaa9d
Add missing catch when querying stat
ASankaran 37cd7cf
Write all registration stats to db on signup
ASankaran ad7f1aa
Fixed mail list bug in RSVPController
ASankaran 326b893
Update stats on attendee rsvp
ASankaran 2ed2ce5
Update liveevent attendee count on checkin
ASankaran c989637
Write stats into cache on increment
ASankaran 58134fa
Added function to stats back from database if needed
ASankaran 614c8bd
Fetch stats from cache when possible, falling back to database when n…
ASankaran 66a5a1d
Ran linter and removed old stats code
ASankaran 29e1fcb
Added stats for tracked live events
ASankaran c37fa6e
Ran linter
ASankaran 0c2b679
Updated Docs
ASankaran 320f523
Merge pull request #214 from HackIllinois/staging
YashoSharma 212c4cc
Merged master
ASankaran 8560392
Rename liveevent to live_event
ASankaran eee93e3
Write stats to cache in series
ASankaran 2c7d064
Decrement RSVP stats on changing accept to decline
ASankaran 6b4b68c
Removed stats test
ASankaran d54acb4
Reverted rsvp tests
ASankaran 7144f39
Removed unused stat function
ASankaran 14ed003
Refactored stats increment calls
ASankaran 9ca2538
Removed promise nesting
ASankaran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
const _ = require('lodash'); | ||
|
||
const Model = require('./Model'); | ||
const validators = require('../utils/validators'); | ||
|
||
const CATEGORIES = ['registration', 'rsvp', 'live_event']; | ||
|
||
const Stat = Model.extend({ | ||
tableName: 'stats', | ||
idAttribute: 'id', | ||
validations: { | ||
category: ['required', 'string', validators.in(CATEGORIES)], | ||
stat: ['required', 'string'], | ||
field: ['required', 'string'], | ||
count: ['required', 'integer'] // Change to default 0? | ||
} | ||
}); | ||
|
||
/** | ||
* Adds a row with category `category`, stat `stat`, and field `field`. | ||
* Initializes count to 0 | ||
* @param {String} category | ||
* @param {String} stat | ||
* @param {String} field | ||
* @return {Promise<Stat>} a Promise resolving to the newly-created Stat | ||
*/ | ||
Stat.create = (category, stat, field) => { | ||
const s = Stat.forge({ | ||
category: category, | ||
stat: stat, | ||
field: field, | ||
count: 0 | ||
}); | ||
|
||
return s.save(); | ||
}; | ||
|
||
/** | ||
* Increments the specified stat by the amount | ||
* @param {String} category | ||
* @param {String} stat | ||
* @param {String} field | ||
* @param {Number} amount defaults to 1 | ||
* @return {Promise<Stat>} a Promise resolving to the updating Stat model | ||
*/ | ||
Stat.increment = (category, stat, field, amount) => { | ||
if (_.isUndefined(amount)) { | ||
amount = 1; | ||
} | ||
|
||
const s = Stat.where({ | ||
category: category, | ||
stat: stat, | ||
field: field | ||
}).fetch(); | ||
|
||
return s.then((model) => { | ||
if(model == null) { | ||
return Stat.create(category, stat, String(field)).then((createdModel) => { | ||
createdModel.set('count', createdModel.get('count') + amount); | ||
return createdModel.save(); | ||
}); | ||
} | ||
model.set('count', model.get('count') + amount); | ||
return model.save(); | ||
|
||
}).catch(() => null); | ||
}; | ||
|
||
module.exports = Stat; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this is necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stats Service needs it to query all the tracked events and report the number of people who checked in.