Add word count to Stats
Categories
(Webtools Graveyard :: Pontoon, defect, P3)
Tracking
(firefox44 affected)
Tracking | Status | |
---|---|---|
firefox44 | --- | affected |
People
(Reporter: mathjazz, Assigned: karskaja)
References
Details
Comment 2•9 years ago
|
||
Reporter | ||
Comment 3•9 years ago
|
||
Reporter | ||
Updated•9 years ago
|
Reporter | ||
Comment 6•7 years ago
|
||
Would the maintainers be open to a contribution implementing this feature -- or, at least, laying the groundwork for it by adding total_words, translated_words, etc. to the db models?
Reporter | ||
Comment 8•5 years ago
|
||
(In reply to Anand from comment #7)
Would the maintainers be open to a contribution implementing this feature -- or, at least, laying the groundwork for it by adding total_words, translated_words, etc. to the db models?
Yes and yes. :)
I started poking around at the word count thing today, and I've got a strategy question: it looks to me like it would be worthwhile to store a word_count
field on the Entity model (even though it's derivable from the string data) because this would allow for updating an analogous, aggregated field on Resource without fetching all the strings from the db.
One way to do this would be to overload the Entity class's constructor so that word_count
is always set. But Django docs seem to suggest that overloading model constructors isn't idiomatic
Another way would be to add a static factory method for creating Entity objects, but I worry then that it would be easy for future contributors to introduce a bug by constructing Entity directly.
Matjaz: what do you think?
Reporter | ||
Comment 10•5 years ago
|
||
I like the idea of adding the Entity.word_count
field for the reasons you mentioned.
You can override the Entity.save() method, which will be called when we create newly added entities during sync:
https://github.com/mozilla/pontoon/blob/master/pontoon/sync/changeset.py#L218
However the method will not be called when we bulk_create or bulk_update Entities:
https://github.com/mozilla/pontoon/blob/master/pontoon/administration/views.py#L387
https://github.com/mozilla/pontoon/blob/master/pontoon/sync/changeset.py#L382
I'm afraid we'll have to manually maintain word_count
the in such cases.
I also don't think we have other cases in the codebase currently that change the Entity table beyond the ones I'm linking to.
Comment 11•5 years ago
|
||
Hi everyone!
:Anand
I like the idea of a separate field for the number of words in the Entity model. Unfortunately
Comment 12•5 years ago
|
||
Sorry everyone, I posted a draft comment by a mistake. I wrote about this on IRC: The idea of an additional field is good, but you can't use the constructor of the Entity model because it will not work in places where bulk_*
functions change the state of entities.
I'll follow this bug and I'll ping you if something better comes to my mind.
Comment 13•5 years ago
|
||
:jotes
What if we also update bulk_create
and bulk_update
in EntityQuerySet
?
Comment 14•5 years ago
|
||
:Anand
I like this concept. But there's a small implementation detail :-) Pontoon doesn't use bulk_create
to make new entities during the sync process.
Look at: https://github.com/mozilla/pontoon/blob/f9c1aa4b0d319c0247dbf721ba99c485a2df3591/pontoon/sync/changeset.py#L218
The sync process calls the get_or_create
method. It's because the id of an entity is required to add translations of the entity into the database. I think you can override it.
bulk_update
is not available in the version of Django that's on the master branch of Pontoon. As a temporary solution, you can add a method with the same name to the Entity
query set class and just call the bulk_update
function from django-bulk-update
library. It will be removed when Django 2.0 lands in Pontoon.
However, I would suggest to split the overall change into two smaller pull requests. The first pull request would introduce new methods and do a refactoring and the second pull request would contain all changes related to the number of words in an Entity.
This approach may help with the review process (the smaller pr, the better) :)
:mathjazz what do you think about these ideas?
Reporter | ||
Comment 15•5 years ago
|
||
Thanks for chiming in, :jotes!
I like Anand's idea and your proposal a lot. Let's go for it!
Reporter | ||
Comment 16•5 years ago
|
||
Anand, this bug has been stuck for a while, so I'm reassigning it to Karskaya.
Reporter | ||
Comment 17•5 years ago
|
||
Updated•3 years ago
|
Description
•