-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: master
Are you sure you want to change the base?
Conversation
The code both in the logScanned and template introduces duplication. |
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.
there s a bug
cannot accept code duplication
@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. |
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.
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)), | ||
}); |
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.
this is noise, refrain from doing cosmetic changes.
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.
you may understand why if you try the git blame command
googleSpreadsheet.js
Outdated
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; |
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.
potential security issue in leaking spreadsheet link to front end
hard coded value is pretty bad.
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.
agree, why do we need a cellRef here ?
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.
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.
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.
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; |
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.
redundant
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.
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> |
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.
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
googleSpreadsheet.js
Outdated
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; |
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.
agree, why do we need a cellRef here ?
great job! |
@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. |
@Spazcool, yes it's for the content editors mostly which needs to "debug" data. Some reference concept: 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. |
Pushed some simplifications on that code |
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.
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
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.
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) |
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.
off topic
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.
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 }); |
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.
break behaviour , it should be / instead of
Besides, it's off topic with the current branch
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'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
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.
if current page is not root folder then it will assume the uuid is a subfolder
googleSpreadsheet.js
Outdated
} | ||
o.cellRef = 'https://docs.google.com/spreadsheets/d/1QHKa3vUpht7zRl_LEzl3BlUbolz3ZiL8yKHzdBL42dY/edit#gid=0&range=A' + index + ':T' + index; | ||
return o; | ||
return formatedRow; | ||
} |
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.
not a good practice to mix refactoring and altering behaviour ( i.e. deleting cellRef)
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.
and now the template for http:///recent
display irrelevant links to home page.
googleSpreadsheet.js
Outdated
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); | ||
}); |
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.
introducing redundant local variable is not recommended. It can be a symptom of poor function breakdown
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 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
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.
Extracting local variable is usually bad design.
Extracting subfunction is fine (while inlining others maybe)
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 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 ?
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.
- extracting sub function https://refactoring.com/catalog/extractMethod.html
- removing local variables https://refactoring.com/catalog/inlineTemp.html
app.js
Outdated
allMatches[0].double = true; | ||
|
||
const duplicatedItem = item; | ||
|
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.
duplicatedItem
is redundant with item
we don't need 2 names for 1 thing.
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 know if item is a reference or a copy.
I wanted to ensure it is a copy because I am writing in it.
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 think this is creating any copy.
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 need to recheck that, but if that is a reference, then I need the local variable
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.
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> |
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.
@mpsido nice! Are there other areas in the code where this rewrite should be applied?
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.
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 ;)
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 mean do it.
@@ -6,28 +6,26 @@ const { loadDatabase, searchDatabase } = require('./googleSpreadsheet'); | |||
|
|||
const app = express(); | |||
|
|||
const allScans = []; | |||
const allScans = new Map(); | |||
|
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.
why?
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.
Because I want to avoid repetitions in the "recent" page.
I want to add one by one unique items on that page
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.
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
@lenzai what are the introduced bugs you are talking about ? |
Closing this pull request |
shall we merge it and close the associated issue ? |
@lenzai what do you think we should do with this PR |
Kudos, SonarCloud Quality Gate passed!
|
REFACTOR: logScanned to catch doubled UUIDs & render doubles on template