Skip to content

Log items that share the same UUID #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

Log items that share the same UUID #53

wants to merge 17 commits into from

Conversation

Spazcool
Copy link
Contributor

REFACTOR: logScanned to catch doubled UUIDs & render doubles on template

@lenzai
Copy link
Member

lenzai commented Dec 17, 2017

image

I managed to crash the "page not found" in this branch.

@lenzai
Copy link
Member

lenzai commented Dec 17, 2017

The code both in the logScanned and template introduces duplication.

Copy link
Member

@lenzai lenzai left a comment

Choose a reason for hiding this comment

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

there s a bug

cannot accept code duplication

@Spazcool
Copy link
Contributor Author

@lenzai should be better now. I removed that bug you found as well as the duplicated code. I also added links to item's row in the spreadsheet, should an edit be desired.

Copy link
Member

@lenzai lenzai left a comment

Choose a reason for hiding this comment

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

seems that we are in rabbit hole of moving around more and more information. (i.e. increasing coupling and thus technical debt) in order to just print the perfect logging message.

Logging is supposed to help debugging the application.
Increasing complexity sooner or later will create bugs or at least increase maintenance cost.

app.js Outdated
matches: searchDatabase(req.query, allItems)
.sort((a, b) => (a.floor === b.floor ? 0 : +(a.floor > b.floor) || -1)),
matches: searchDatabase(req.query, allItems).sort((a, b) =>
(a.floor === b.floor ? 0 : +(a.floor > b.floor) || -1)),
});
Copy link
Member

Choose a reason for hiding this comment

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

this is noise, refrain from doing cosmetic changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

you may understand why if you try the git blame command

const o = {};
for (let i = 0; i < lab.length; i += 1) {
o[lab[i]] = val[i];
}
o.cellRef = 'https://docs.google.com/spreadsheets/d/1QHKa3vUpht7zRl_LEzl3BlUbolz3ZiL8yKHzdBL42dY/edit#gid=0&range=A' + index + ':T' + index;
return o;
Copy link
Member

Choose a reason for hiding this comment

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

potential security issue in leaking spreadsheet link to front end

hard coded value is pretty bad.

Copy link
Contributor

Choose a reason for hiding this comment

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

agree, why do we need a cellRef 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.

Not a necessary addition but, I thought having a link to any troublesome item's place in the spreadsheet would be useful for whoever has to edit it.

Copy link
Contributor

Choose a reason for hiding this comment

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

that is a fair concern, and actually you can argue that google spreadsheet retrains access rights to the priviledged users.

on further development we may need a better strategy for that spreadsheet bug fixing.

All that said I still approve that pull request

app.js Outdated
return;
}
function logScanned(uuid, matches) {
let allMatches = matches;
Copy link
Member

Choose a reason for hiding this comment

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

redundant

Copy link
Contributor Author

@Spazcool Spazcool Dec 20, 2017

Choose a reason for hiding this comment

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

Probably not the right way to deal with it but, this in particular was to avoid linter errors.

views/recent.ejs Outdated
: <br/>
<a href="/<%- allScans[i].uuid %>"><%- allScans[i].uuid %></a>
<% if (!allScans[i].fixture) { %>
<a href="<%- allScans[i].link %>" style="color: <%- allScans[i].status === 'fixed' ? 'orange' : 'red' %>">Missing Details!</a>
Copy link
Contributor

Choose a reason for hiding this comment

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

it makes sense to edit style inline here because all we want is to change a color.
but it makes the job of a designer who only knows css more difficult.
consider just giving a style class (class=fixed or class=broken) and edit that style in the css file

const o = {};
for (let i = 0; i < lab.length; i += 1) {
o[lab[i]] = val[i];
}
o.cellRef = 'https://docs.google.com/spreadsheets/d/1QHKa3vUpht7zRl_LEzl3BlUbolz3ZiL8yKHzdBL42dY/edit#gid=0&range=A' + index + ':T' + index;
return o;
Copy link
Contributor

Choose a reason for hiding this comment

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

agree, why do we need a cellRef here ?

@mpsido
Copy link
Contributor

mpsido commented Dec 20, 2017

great job!

@Spazcool
Copy link
Contributor Author

@lenzai I thought the logging here was for whoever is editing the spreadsheets not whoever is debugging the code, even if both groups can use the logs.

@lenzai
Copy link
Member

lenzai commented Dec 20, 2017

@Spazcool, yes it's for the content editors mostly which needs to "debug" data.
Requirements and enhancement you defined are really thoughtful. it's just that the implementation need to be simplified.

Some reference concept:
https://en.wikipedia.org/wiki/Coupling_(computer_programming)
https://en.wikipedia.org/wiki/Encapsulation_(computer_programming)

It's quite difficult to discuss remotely, without either dictating you step by step what to do or just publishing revised code myself. If above links inspire you, feel free to discuss or commit further. Otherwise, we can have a pair programming session in January.

PS: So far, most of the code reviews by @mpsido were published through a mobile phone... I think I fixed that today.

@mpsido
Copy link
Contributor

mpsido commented Dec 20, 2017

Pushed some simplifications on that code

Copy link
Member

@lenzai lenzai left a comment

Choose a reason for hiding this comment

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

not a good practice to mix refactoring and altering behaviour ( i.e. deleting cellRef)

renaming is thoughtful

introducing redundant local variable is not recommended. It can be a symptom of poor function breakdown

Copy link
Member

@lenzai lenzai left a comment

Choose a reason for hiding this comment

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

some steps towards less complexity ( improved encapsulation and naming)
some off topic changes
introducing multiple bugs

see code comments for details

app.js Outdated
@@ -75,6 +75,9 @@ app.get('/:uuid', (req, res) => {
return;
}
logScanned(req.params.uuid, matches);
if (matches.length >= 1) {
console.log(`Too much matches for uuid ${req.params.uuid} length = ${matches.length}`);
}
matches[0].similarItems = searchDatabase({ fixture: matches[0].fixture }, allItems)
Copy link
Member

Choose a reason for hiding this comment

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

off topic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps amateur questions, but why remove the hard URL and how else do we get a link to work?

app.js Outdated
@@ -54,7 +54,7 @@ app.get('/qrlist', (req, res) => {
.filter(item => item.uuid !== '')
.filter(item => item.uuid !== undefined)
.sort((a, b) => (a.floor === b.floor ? 0 : +(a.floor > b.floor) || -1));
qrList.forEach(item => item.qr = qr.imageSync('http://url.coderbunker.com/' + item.uuid, { type: 'svg' }));
qrList.forEach(item => item.qr = qr.imageSync(item.uuid, { type: 'svg' }));
res.render('qrList', { matches: qrList });
Copy link
Member

Choose a reason for hiding this comment

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

break behaviour , it should be / instead of

Besides, it's off topic with the current branch

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll fix that, in which case it won't work ? I need to reproduce it so that I ensure the change will fix that case

Copy link
Member

Choose a reason for hiding this comment

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

if current page is not root folder then it will assume the uuid is a subfolder

}
o.cellRef = 'https://docs.google.com/spreadsheets/d/1QHKa3vUpht7zRl_LEzl3BlUbolz3ZiL8yKHzdBL42dY/edit#gid=0&range=A' + index + ':T' + index;
return o;
return formatedRow;
}
Copy link
Member

Choose a reason for hiding this comment

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

not a good practice to mix refactoring and altering behaviour ( i.e. deleting cellRef)

Copy link
Member

Choose a reason for hiding this comment

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

and now the template for http:///recent display irrelevant links to home page.

const columns = response.values[0];
// map function transforms a list into another list using the given lambda function
const formatedRows = response.values.map(row => spreadsheetValuesToObject(row, columns));
return callback(formatedRows);
});
Copy link
Member

Choose a reason for hiding this comment

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

introducing redundant local variable is not recommended. It can be a symptom of poor function breakdown

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually meant to break into two steps for better readability,
All the things where nested into one line of code that was a headache to read

Copy link
Member

Choose a reason for hiding this comment

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

Extracting local variable is usually bad design.
Extracting subfunction is fine (while inlining others maybe)

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand what "Extracting subfunction" means.
If javascript is smart (and I assume it is), formatedRows is passed by reference.
It does improve readbility don't you think so ?

Copy link
Member

Choose a reason for hiding this comment

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

app.js Outdated
allMatches[0].double = true;

const duplicatedItem = item;

Copy link
Member

Choose a reason for hiding this comment

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

duplicatedItem is redundant with item we don't need 2 names for 1 thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if item is a reference or a copy.
I wanted to ensure it is a copy because I am writing in it.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is creating any copy.

Copy link
Contributor

Choose a reason for hiding this comment

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

I need to recheck that, but if that is a reference, then I need the local variable

Copy link
Member

Choose a reason for hiding this comment

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

not really useful reply

views/recent.ejs Outdated
@@ -2,21 +2,21 @@
<h1>Recently scanned QR codes</h1>
<article class="col-xs-12">
<ul class='recent-list'>
<% for (var i = 0; i < allScans.length; i++) { %>
<% for (let item of allScans.values()) { %>
<li>
Copy link
Member

Choose a reason for hiding this comment

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

@mpsido nice! Are there other areas in the code where this rewrite should be applied?

Copy link
Contributor

Choose a reason for hiding this comment

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

Everywhere there is a for loop ;) if you don't care about the index then you can use for..in or for..of.
See the MSDN documentation to understand the difference ;)

Copy link
Member

Choose a reason for hiding this comment

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

I mean do it.

@@ -6,28 +6,26 @@ const { loadDatabase, searchDatabase } = require('./googleSpreadsheet');

const app = express();

const allScans = [];
const allScans = new Map();

Copy link
Member

Choose a reason for hiding this comment

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

why?

Copy link
Contributor

Choose a reason for hiding this comment

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

Because I want to avoid repetitions in the "recent" page.
I want to add one by one unique items on that page

Copy link
Member

Choose a reason for hiding this comment

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

This is not the way to handle changes and features. We create an issue, discuss it and push it.
Hidding secret features in unrelated commits is not appropriate decision workflow and distracting for code review

@mpsido
Copy link
Contributor

mpsido commented Dec 21, 2017

@lenzai what are the introduced bugs you are talking about ?

@mpsido
Copy link
Contributor

mpsido commented Dec 27, 2017

Closing this pull request
see that one instead:
#62

@mpsido mpsido closed this Dec 27, 2017
@mpsido mpsido mentioned this pull request Dec 27, 2017
@mpsido mpsido reopened this Dec 29, 2017
@mpsido
Copy link
Contributor

mpsido commented Jan 1, 2018

shall we merge it and close the associated issue ?

@mpsido
Copy link
Contributor

mpsido commented Jan 5, 2018

@lenzai what do you think we should do with this PR

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants