Skip to content

Conversation

@michaelawyu
Copy link
Contributor

As requested by Steren.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Dec 7, 2018
@michaelawyu michaelawyu requested a review from ace-n December 7, 2018 21:06
Copy link
Contributor

@MylesBorins MylesBorins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Some nits inline about when to use an async function and about some of the logic that moved around

const GA_TRACKING_ID = process.env.GA_TRACKING_ID;

function trackEvent(category, action, label, value) {
async function trackEvent(category, action, label, value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are not using the await keyword inside the function I don't believe we need to convert it to an async function. We should still be able to await the function if it returns a thenable (e.g. promise)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks!

.order('timestamp', {descending: true})
.limit(10);

return datastore.runQuery(query).then(results => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this logic moved somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's moved to the "/" hander function (~Line 73):

function getVisits() {..}

app.get('/', async (req, res, next) => {
...
let results = await getVisits();
let entities = results[0];
    let visits = entities.map(
      entity => `Time: ${entity.timestamp}, AddrHash: ${entity.userIp}`
    );
...

.catch(next);
try {
await insertVisit(visit);
let results = await getVisits();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason to use let instead of const here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks!

Copy link
Contributor

@ace-n ace-n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once my + @MylesBorins comments are addressed.

* @param {object} visit The visit record to insert.
*/
function insertVisit(visit) {
async function insertVisit(visit) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto to @MylesBorins above comment - do we need this async?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks!

* Retrieve the latest 10 visit records from the database.
*/
function getVisits() {
async function getVisits() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this async?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks!

'http://metadata.google.internal/computeMetadata/v1/project/project-id';

function getProjectId() {
async function getProjectId() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this async?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks!

env_variables:
PUBSUB_TOPIC: YOUR_TOPIC_NAME
#PUBSUB_TOPIC: YOUR_TOPIC_NAME
PUBSUB_TOPIC: sample-topic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did/will you update the docs accordingly, if necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks!

@michaelawyu michaelawyu merged commit 2cd7fe3 into master Dec 8, 2018
@michaelawyu michaelawyu deleted the michaelawyu-patch-appengine-async branch December 8, 2018 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants