The POFileTranslator table is an eager materialized view, containing references to the most recent posubmission made by a particular person to a particular pofile. This table is read only to most users, but for this test we connect as a superuser so we can poke at it directly. >>> from lp.services.database.sqlbase import connect >>> connection = connect(user='testadmin') >>> cur = connection.cursor() >>> def pofiletranslator(person_id, pofile_id): ... cur.execute(""" ... SELECT latest_message, date_last_touched ... FROM POFileTranslator ... WHERE person = %(person_id)s AND pofile = %(pofile_id)s ... """, vars()) ... result = cur.fetchone() ... if result is None: ... return None ... return list(result) >>> stub_id = 22 >>> pofile_id = 1 >>> language_id = 387 >>> potmsgset_id = 1 Note that our oldest TranslationMessage belongs to pofile #1. Stub has so far not translated anything in this pofile >>> pofiletranslator(stub_id, pofile_id) is None True If we add a message, the cache is updated >>> cur.execute(""" ... INSERT INTO TranslationMessage( ... potmsgset, msgstr1, origin, submitter, language ... ) VALUES ( ... %(potmsgset_id)s, 1, 1, %(stub_id)s, %(language_id)s) ... """, vars()) >>> posubmission_id, date_touched = pofiletranslator(stub_id, pofile_id) We now set the last touched timestamp into the past so we can detect that it is correctly updated. This is only possible because we are connected to the database as the testadmin user. >>> cur.execute(""" ... UPDATE POFileTranslator ... SET date_last_touched = CURRENT_TIMESTAMP - '1 day'::interval ... WHERE person=%(stub_id)s AND pofile=%(pofile_id)s ... """, vars()) If we add a new submission to that pofile, the cache is updated including the last touched timestamp. >>> cur.execute(""" ... INSERT INTO TranslationMessage( ... potmsgset, msgstr1, origin, submitter, language ... ) VALUES ( ... %(potmsgset_id)s, 2, 1, %(stub_id)s, %(language_id)s) ... """, vars()) >>> new_posubmission_id, new_date_touched = pofiletranslator( ... stub_id, pofile_id) >>> posubmission_id == new_posubmission_id False We should get the same timestamp as before, despite having updated the cache manually, as we are in the same database transaction and CURRENT_TIMESTAMP will return a constant value throughout the transaction and the triggers will have reset the value in the cache. >>> date_touched == new_date_touched True If we update the submissin, the cache is updated >>> mark_id = 1 >>> cur.execute(""" ... UPDATE TranslationMessage SET submitter=%(mark_id)s ... WHERE id = %(new_posubmission_id)s ... """, vars()) >>> mark_posubmission_id, date_touched = pofiletranslator( ... mark_id, pofile_id) >>> stub_posubmission_id, date_touched = pofiletranslator( ... stub_id, pofile_id) >>> mark_posubmission_id == stub_posubmission_id False The trigger was smart enough to locate the previous submission from stub >>> stub_posubmission_id == posubmission_id True