Skip to content

Commit

Permalink
wip?
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSquires committed May 30, 2024
1 parent 23a637a commit 69cfae1
Showing 1 changed file with 42 additions and 15 deletions.
57 changes: 42 additions & 15 deletions synapse/lib/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4109,8 +4109,28 @@ async def iterLayerAddPerms(self):

break

# tagprops
for byts, abrv in self.tagpropabrv.slab.scanByFull(db=self.tagpropabrv.name2abrv):
info = s_msgpack.un(byts)
if None in info or len(info) != 3:
continue

for _ in self.layrslab.scanByPref(abrv, db=self.bytagprop):
yield ('node', 'tag', 'add', *info[1].split('.'))
break

# nodedata
for abrv in self.dataslab.scanKeys(db=self.dataname):
name, _ = self.getAbrvProp(abrv)
yield ('node', 'data', 'set', name)

# edges
for verb in self.layrslab.scanKeys(db=self.byverb):
yield ('node', 'edge', 'add', verb.decode())

# tags
# NB: tag perms should be yielded for every leaf on every node in the layer
'''
await self._saveDirtySodes()
for buid, byts in self.layrslab.scanByFull(db=self.bybuidv3):
sode = s_msgpack.un(byts)
Expand All @@ -4133,25 +4153,32 @@ async def iterLayerAddPerms(self):
for key, count in seen.items():
if count == 1:
yield ('node', 'tag', 'add', *key)
'''
tags = {}

# tagprops
for byts, abrv in self.tagpropabrv.slab.scanByFull(db=self.tagpropabrv.name2abrv):
info = s_msgpack.un(byts)
if None in info or len(info) != 3:
continue
@s_cache.memoize()
def tagNameByAbrv(abrv):
return self.tagabrv.abrvToName(abrv)

for _ in self.layrslab.scanByPref(abrv, db=self.bytagprop):
yield ('node', 'tag', 'add', *info[1].split('.'))
break
for lkey, buid in self.layrslab.scanByFull(db=self.bytag):
abrv = lkey[:8]
tags.setdefault(buid, [])
tags[buid].append(abrv)

# nodedata
for abrv in self.dataslab.scanKeys(db=self.dataname):
name, _ = self.getAbrvProp(abrv)
yield ('node', 'data', 'set', name)
for buid, abrvs in tags.items():
seen = {}

# edges
for verb in self.layrslab.scanKeys(db=self.byverb):
yield ('node', 'edge', 'add', verb.decode())
for abrv in abrvs:
tag = tagNameByAbrv(abrv)
parts = tag.split('.')
for idx in range(1, len(parts) + 1):
key = tuple(parts[:idx])
seen.setdefault(key, 0)
seen[key] += 1

for key, count in seen.items():
if count == 1:
yield ('node', 'tag', 'add', *key)

async def iterLayerDelPerms(self): # pragma: no cover
# TODO: Implement me for Syn3.x
Expand Down

0 comments on commit 69cfae1

Please sign in to comment.