synapse 2.186.0__py311-none-any.whl → 2.187.1__py311-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of synapse might be problematic. Click here for more details.

synapse/lib/spooled.py CHANGED
@@ -7,6 +7,9 @@ import synapse.lib.const as s_const
7
7
  import synapse.lib.msgpack as s_msgpack
8
8
  import synapse.lib.lmdbslab as s_lmdbslab
9
9
 
10
+ MAX_SPOOL_SIZE = 10000
11
+ DEFAULT_MAPSIZE = s_const.mebibyte * 32
12
+
10
13
  class Spooled(s_base.Base):
11
14
  '''
12
15
  A Base class that can be used to implement objects which fallback to lmdb.
@@ -15,7 +18,7 @@ class Spooled(s_base.Base):
15
18
  together. Under memory pressure, these objects have a better shot of getting paged out.
16
19
  '''
17
20
 
18
- async def __anit__(self, dirn=None, size=10000, cell=None):
21
+ async def __anit__(self, dirn=None, size=MAX_SPOOL_SIZE, cell=None):
19
22
  '''
20
23
  Args:
21
24
  dirn(Optional[str]): base directory used for backing slab. If None, system temporary directory is used
@@ -46,7 +49,7 @@ class Spooled(s_base.Base):
46
49
 
47
50
  slabpath = tempfile.mkdtemp(dir=dirn, prefix='spooled_', suffix='.lmdb')
48
51
 
49
- self.slab = await s_lmdbslab.Slab.anit(slabpath, map_size=s_const.mebibyte * 32)
52
+ self.slab = await s_lmdbslab.Slab.anit(slabpath, map_size=DEFAULT_MAPSIZE)
50
53
  if self.cell is not None:
51
54
  self.slab.addResizeCallback(self.cell.checkFreeSpace)
52
55
 
@@ -55,7 +58,7 @@ class Set(Spooled):
55
58
  A minimal set-like implementation that will spool to a slab on large growth.
56
59
  '''
57
60
 
58
- async def __anit__(self, dirn=None, size=10000, cell=None):
61
+ async def __anit__(self, dirn=None, size=MAX_SPOOL_SIZE, cell=None):
59
62
  await Spooled.__anit__(self, dirn=dirn, size=size, cell=cell)
60
63
  self.realset = set()
61
64
  self.len = 0
@@ -84,6 +87,27 @@ class Set(Spooled):
84
87
 
85
88
  return len(self.realset)
86
89
 
90
+ async def copy(self):
91
+ newset = await Set.anit(dirn=self.dirn, size=self.size, cell=self.cell)
92
+
93
+ if self.fallback:
94
+ await newset._initFallBack()
95
+ await self.slab.copydb(None, newset.slab)
96
+ newset.len = self.len
97
+
98
+ else:
99
+ newset.realset = self.realset.copy()
100
+
101
+ return newset
102
+
103
+ async def clear(self):
104
+ if self.fallback:
105
+ self.len = 0
106
+ await self.slab.trash()
107
+ await self._initFallBack()
108
+ else:
109
+ self.realset.clear()
110
+
87
111
  async def add(self, valu):
88
112
 
89
113
  if self.fallback:
@@ -117,7 +141,7 @@ class Set(Spooled):
117
141
 
118
142
  class Dict(Spooled):
119
143
 
120
- async def __anit__(self, dirn=None, size=10000, cell=None):
144
+ async def __anit__(self, dirn=None, size=MAX_SPOOL_SIZE, cell=None):
121
145
 
122
146
  await Spooled.__anit__(self, dirn=dirn, size=size, cell=cell)
123
147
  self.realdict = {}
synapse/lib/storm.py CHANGED
@@ -5979,6 +5979,13 @@ class RunAsCmd(Cmd):
5979
5979
 
5980
5980
  NOTE: This command requires admin privileges.
5981
5981
 
5982
+ NOTE: Heavy objects (for example a View or Layer) are bound to the context which they
5983
+ are instantiated in and methods on them will be run using the user in that
5984
+ context. This means that executing a method on a variable containing a heavy
5985
+ object which was instantiated outside of the runas command and then used
5986
+ within the runas command will check the permissions of the outer user, not
5987
+ the one specified by the runas command.
5988
+
5982
5989
  Examples:
5983
5990
 
5984
5991
  // Create a node as another user.