Skip to content
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

Merged

Conversation

abulte
Copy link
Contributor

@abulte abulte commented Oct 23, 2017

No description provided.

@abulte abulte requested a review from a team October 23, 2017 09:54
@@ -39,6 +39,13 @@ new Vue({
userReuses: []
};
},
computed: {
limitCheckDate() {
let limitDate = new Date();
Copy link
Contributor

Choose a reason for hiding this comment

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

s/let/const/

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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 }}"
Copy link
Contributor

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:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

* @param {Object} resource_el A resource element from DOM
*/
getCachedCheck(resource_el) {
const extras = JSON.parse(resource_el.dataset.extras);
Copy link
Contributor

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)

if (extras['check:date']) {
const checkDate = new Date(extras['check:date']);
if (checkDate >= this.limitCheckDate) {
return Object.keys(extras).reduce(function(obj, key) {
Copy link
Member

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 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

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 think an arrow function is relevant here, it only adds the extra cost of scoping without being used

Copy link
Member

Choose a reason for hiding this comment

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

Micro-perf vs. consistency

Copy link
Contributor

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)

@@ -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 }}" />
Copy link
Member

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)?

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

@noirbizarre noirbizarre left a 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 👍

@@ -90,6 +90,19 @@
MAX_DISTANCE = 2


class JsonLdExtrasMixin(object):

@staticmethod
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 think having a static method is useful. A simple helper function should do the job

@@ -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,
Copy link
Contributor

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.

@@ -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 }}" />
Copy link
Contributor

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

@abulte abulte force-pushed the linkchecker/get-initial-status-in-template branch from cba1cfb to 2b56891 Compare October 24, 2017 16:47
@abulte abulte merged commit aefa821 into opendatateam:master Oct 24, 2017
@abulte abulte deleted the linkchecker/get-initial-status-in-template branch October 24, 2017 16:53
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.

None yet

3 participants