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
Get cached linkchecker result before hitting API #1235
Get cached linkchecker result before hitting API #1235
Conversation
js/front/dataset/index.js
Outdated
@@ -39,6 +39,13 @@ new Vue({ | |||
userReuses: [] | |||
}; | |||
}, | |||
computed: { | |||
limitCheckDate() { | |||
let limitDate = new Date(); |
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.
s/let/const/
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.
Sure? It's mutated below.
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.
const
in JS does not define a constant value but a const reference, ie. limitDate
is not reaffected so it's a const. The fact that it's mutated or not is not taken in account in the choice between let
or const
.
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.
Yes, my comment was more about style than technical capability. I still have some mental trouble with some being called const and then its value being changed... Anyway, I’ll change that, no biggy.
@@ -1,6 +1,7 @@ | |||
{% set resource_format = resource.format|trim|lower or 'data' %} | |||
<div id="resource-{{resource.id}}" class="list-group-item" | |||
data-checkurl="{{ url_for('api.check_dataset_resource', dataset=dataset.id, rid=resource.id) }}" | |||
data-extras="{{ resource.extras|to_json }}" |
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.
Maybe reuse the json-ld
already used in this page to serialize structured data (data and its extras, ressources...).
See:
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.
👍
js/front/dataset/index.js
Outdated
* @param {Object} resource_el A resource element from DOM | ||
*/ | ||
getCachedCheck(resource_el) { | ||
const extras = JSON.parse(resource_el.dataset.extras); |
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 think to reduce JSON parsing (ie. more than 200 on SIRENE), it would be better to parse once from json-ld (and so also reuse the already in place mecanism)
js/front/dataset/index.js
Outdated
if (extras['check:date']) { | ||
const checkDate = new Date(extras['check:date']); | ||
if (checkDate >= this.limitCheckDate) { | ||
return Object.keys(extras).reduce(function(obj, key) { |
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.
Arrow function for the win :)
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 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 an arrow function is relevant here, it only adds the extra cost of scoping without being used
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.
Micro-perf vs. consistency
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.
These are not 2 equivalent syntaxes so consistency is not relevant. On the breaking cases (which we fixed by switching back on functions), what should we do ? Keep a bug for consistency ?
This is not at all about micro-perfs but about the fact that over-using arrow functions when it's not necessary introduced bugs before (and I'm pretty sure there still is) and so being mechanical about the use of it is not safe (mostly because these bugs are a pain to detect and so a big useless loss of time)
udata/templates/macros/metadata.html
Outdated
@@ -47,6 +47,7 @@ | |||
{% endif %} | |||
|
|||
<meta name="check-urls" content="{{ config.LINKCHECKING_ENABLED|tojson }}" /> | |||
<meta name="check-urls-cache-duration" content="{{ config.LINKCHECKING_CACHE_DURATION|tojson }}" /> |
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.
Is the |tojson
filter still pertinent for numeric values (vs. boolean)?
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.
Agreed, does not transform anything
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 test, probably not.
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.
Yes, way better !
Just transform the mixin+static metrhod into a classic function and it's done 👍
udata/core/dataset/models.py
Outdated
@@ -90,6 +90,19 @@ | |||
MAX_DISTANCE = 2 | |||
|
|||
|
|||
class JsonLdExtrasMixin(object): | |||
|
|||
@staticmethod |
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 having a static method is useful. A simple helper function should do the job
udata/core/dataset/models.py
Outdated
@@ -268,7 +283,8 @@ class Resource(ResourceMixin, WithMetrics, db.EmbeddedDocument): | |||
on_deleted = signal('Resource.on_deleted') | |||
|
|||
|
|||
class Dataset(WithMetrics, BadgeMixin, db.Owned, db.Document): | |||
class Dataset(WithMetrics, BadgeMixin, JsonLdExtrasMixin, db.Owned, |
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.
Yes, definitively not a mixin.
udata/templates/macros/metadata.html
Outdated
@@ -47,6 +47,7 @@ | |||
{% endif %} | |||
|
|||
<meta name="check-urls" content="{{ config.LINKCHECKING_ENABLED|tojson }}" /> | |||
<meta name="check-urls-cache-duration" content="{{ config.LINKCHECKING_CACHE_DURATION|tojson }}" /> |
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.
Agreed, does not transform anything
cba1cfb
to
2b56891
Compare
No description provided.