Faster processing by avoiding two writes on creating new entry
This commit is contained in:
parent
3cce2540f3
commit
74afdf1f3a
@ -23,9 +23,19 @@ class UnitManager(models.Manager):
|
||||
'''
|
||||
src = join_plural(unit.source.strings)
|
||||
ctx = unit.getcontext()
|
||||
dbunit, created = self.get_or_create(
|
||||
translation = translation,
|
||||
source = src,
|
||||
context = ctx)
|
||||
dbunit.update_from_unit(unit)
|
||||
import trans.models
|
||||
try:
|
||||
dbunit = self.get(
|
||||
translation = translation,
|
||||
source = src,
|
||||
context = ctx)
|
||||
force = False
|
||||
except:
|
||||
dbunit = trans.models.Unit(
|
||||
translation = translation,
|
||||
source = src,
|
||||
context = ctx)
|
||||
force = True
|
||||
|
||||
dbunit.update_from_unit(unit, force)
|
||||
return dbunit
|
||||
|
@ -203,18 +203,18 @@ class Unit(models.Model):
|
||||
|
||||
objects = UnitManager()
|
||||
|
||||
def update_from_unit(self, unit):
|
||||
def update_from_unit(self, unit, force):
|
||||
location = ', '.join(unit.getlocations())
|
||||
flags = '' # FIXME
|
||||
target = join_plural(unit.target.strings)
|
||||
fuzzy = unit.isfuzzy()
|
||||
if location == self.location and flags == self.flags and target == self.target and fuzzy == self.fuzzy:
|
||||
if not force and location == self.location and flags == self.flags and target == self.target and fuzzy == self.fuzzy:
|
||||
return
|
||||
self.location = location
|
||||
self.flags = flags
|
||||
self.target = target
|
||||
self.fuzzy = fuzzy
|
||||
self.save()
|
||||
self.save(force_insert = force)
|
||||
|
||||
def is_plural(self):
|
||||
return is_plural(self.source)
|
||||
|
Loading…
Reference in New Issue
Block a user