Commit f7a9b31d authored by Aurélien Campéas's avatar Aurélien Campéas
Browse files

log: abandon the stripped option

We still keep the stripped changesets in db because it is basically
impossible to remove them using the current schema.

The foreign keys from series tables to the changeset table
turn it into a neverending operation.

Fix for this will belong to #54.
parent e923b1b92e82
......@@ -1191,19 +1191,14 @@ insertion_date value_date
assert [l['author'] for l in log
] == ['babar', 'celeste', 'babar', 'celeste', 'celeste', 'celeste']
alllogs = tsh.log(engine, stripped=True, names=['xserie', 'yserie'])
log = [rev for rev in alllogs
if rev['meta']
and rev['meta'].get('tshistory.info', '').startswith('got')]
assert len(log) == 2 # 2 stripped csets
for l in log:
assert l['names'] == [] # not good
meta = l['meta']
stripinfo = meta.get('tshistory.info')
assert (stripinfo.startswith('got stripped from') or
# see how this test is silly ?
stripinfo.startswith('belonged to'))
alllogs = tsh.log(engine, names=['xserie', 'yserie'])
assert len(alllogs) == 6
sql = f"""select count(*) from {tsh.namespace}.changeset
where (metadata::jsonb ->> 'tshistory.info')
like 'got stripped%%' """
count = engine.execute(sql).scalar()
assert count == 2
def test_long_name(engine, tsh):
......
......@@ -396,33 +396,28 @@ class timeseries(SeriesServices):
@tx
def strip(self, cn, seriename, csid):
# wipe the diffs
tablename = self._serie_to_tablename(cn, seriename)
sql = (f'delete from "{self.namespace}.timeserie"."{tablename}" '
'where cset >= %(csid)s')
cn.execute(sql, csid=csid)
logs = self.log(cn, fromrev=csid, names=(seriename,))
assert logs
# put stripping info in the metadata
for log in logs:
# update changeset.metadata
metadata = self.changeset_metadata(cn, log['rev']) or {}
csid = log['rev']
# set in metadata the fact that this changeset
# has been stripped (hence is no longer being referenced)
metadata = self.changeset_metadata(cn, csid) or {}
metadata['tshistory.info'] = f'got stripped from {csid}'
sql = (f'update "{self.namespace}".changeset '
'set metadata = %(metadata)s '
'where id = %(id)s')
cn.execute(sql, id=log['rev'], metadata=json.dumps(metadata))
'where id = %(csid)s')
cn.execute(sql, csid=csid, metadata=json.dumps(metadata))
# delete changset_serie item
sql = (f'delete from "{self.namespace}".changeset_series as css '
'where css.cset = %(rev)s '
'and css.serie = %(name)s')
cn.execute(
sql,
rev=log['rev'],
name=self._name_to_regid(cn, seriename)
)
# wipe the diffs
tablename = self._serie_to_tablename(cn, seriename)
sql = (f'delete from "{self.namespace}.timeserie"."{tablename}" '
'where cset >= %(csid)s')
cn.execute(sql, csid=csid)
'where css.cset = %(csid)s')
cn.execute(sql, csid=csid)
snapshot = Snapshot(cn, self, seriename)
snapshot.reclaim()
......@@ -440,7 +435,6 @@ class timeseries(SeriesServices):
return stats
def log(self, cn, limit=0, names=None, authors=None,
stripped=False,
fromrev=None, torev=None,
fromdate=None, todate=None):
"""Build a structure showing the history of all the series in the db,
......@@ -450,17 +444,11 @@ class timeseries(SeriesServices):
sql = [
'select distinct cset.id, cset.author, cset.insertion_date, cset.metadata '
f'from "{self.namespace}".changeset as cset, '
f' "{self.namespace}".registry as reg, '
f' "{self.namespace}".changeset_series as css '
f'from "{self.namespace}".changeset as cset '
f'join "{self.namespace}".changeset_series as css on css.cset = cset.id '
f'join "{self.namespace}".registry as reg on reg.id = css.serie '
]
wheres = []
if stripped:
sql.append(f'left join "{self.namespace}".changeset as cset2 '
'on (cset2.id = css.cset) ')
else:
wheres.append('cset.id = css.cset and '
'css.serie = reg.id ')
if names:
# XXX check names exist
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment