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

Use proxy unit for source_unit when updating from diff #5239

Merged
merged 2 commits into from Sep 13, 2016

Conversation

phlax
Copy link
Member

@phlax phlax commented Sep 12, 2016

When StoreDiff creates its diff of changes the code then retrieves the source units individually (either from the file or the db) - although it already has the information required to update.

This PR uses a proxy class to update the unit without going back to db/fs

this needs tests to ensure that a plural from a source db unit is updated correctly

UPDATE: added some tests to ensure that plural form units are added correctly when copied from db

@phlax phlax changed the title Use proxy unit for source_unit when updating from diff [WIP] Use proxy unit for source_unit when updating from diff Sep 12, 2016
@@ -251,10 +272,14 @@ def diff(self):
"""Return a dictionary of change actions or None if there are no
changes to be made.
"""
diff = {"index": self.get_indexes_to_update(),
Copy link
Contributor

Choose a reason for hiding this comment

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

why can't we leave it as it was?

Copy link
Member Author

Choose a reason for hiding this comment

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

we can i was using debug_sql on it - thats why it changed

@phlax phlax force-pushed the cleanup_proxy_diff branch 2 times, most recently from 3ee3dcf to 6ba1be9 Compare September 13, 2016 14:55
@phlax phlax changed the title [WIP] Use proxy unit for source_unit when updating from diff Use proxy unit for source_unit when updating from diff Sep 13, 2016
unit.save()
newunit = unit.__class__()
newunit.source = multistring(["OTHER NEW TARGET", "OTHER NEW TARGETS"])
newunit.target = "OTHER NEW TARGET"
Copy link
Member

Choose a reason for hiding this comment

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

Does this need some exercising around a multstring based target?

Copy link
Member Author

Choose a reason for hiding this comment

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

perhaps - although this is not something ever checked tested - the issue here was that the proxy class didnt have hasplural so would have failed when adding units to a store

@phlax
Copy link
Member Author

phlax commented Sep 13, 2016

re queries - this PR increases db calls slightly - due to test changes. If we were testing more extensively with db updating it would have more impact on queries.

re timings - this PR seems to improve timings - altho these can be somewhat variable on a local system

before:

TESTS TOTAL test time: 195.282850981
TESTS TOTAL queries: 82177

after

TESTS TOTAL test time: 176.819938898
TESTS TOTAL queries: 82191

worth mentioning that this PR improves stability as much as performance - in that its not going back to the disk to check the units (i believe it was doing this but i would need check that 100%)

def getnotes(self, origin=None):
return self.unit["%s_comment" % origin]

def getcontext(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

@phlax have you considered to put these methods to DiffUnitProxy class?

Copy link
Member Author

Choose a reason for hiding this comment

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

i think they are useful for any unitproxy - no?

Copy link
Contributor

Choose a reason for hiding this comment

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

I used UnitProxy as base class but I didn't use any of its methods here
a56c885

Copy link
Member Author

Choose a reason for hiding this comment

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

fair point - im wondering if its useful outside of diff - here its used in the update too - and what we should call it

@unho
Copy link
Member

unho commented Sep 13, 2016

Commit "Add getcontext, hasplurals, isfuzzy, isobsolete and getid to UnitProxy" message doesn't match its changes.

or getattr(self.source, "plural", None)))

def getnotes(self, origin=None):
return self.unit["%s_comment" % origin]
Copy link
Member

Choose a reason for hiding this comment

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

How does this render in case no origin is specified? Perhaps it is better not to default to None?

Copy link
Member Author

Choose a reason for hiding this comment

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

hm - i think it should return ""

@phlax
Copy link
Member Author

phlax commented Sep 13, 2016

oops - need to move that method - and kill commit...

@phlax phlax force-pushed the cleanup_proxy_diff branch 2 times, most recently from 05d37c9 to 2d71270 Compare September 13, 2016 16:58
@unho
Copy link
Member

unho commented Sep 13, 2016

lgtm

source_unit = self.source_store.findid(uid)
if source_unit and source_unit.getid() not in self.target_units:
source_unit = self.source_units.get(uid)
if source_unit and uid not in self.target_units:
Copy link
Contributor

Choose a reason for hiding this comment

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

uid == source_unit.getid() ?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep

@ta2-1
Copy link
Contributor

ta2-1 commented Sep 13, 2016

lgtm

@phlax phlax merged commit 7f9abb2 into translate:master Sep 13, 2016
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

4 participants