kopia lustrzana https://github.com/snarfed/bridgy-fed
Protocol.load: return copies of cached objects, not the originals
...so that modifications aren't durable in memory until we put() them. for #558pull/561/head
rodzic
02214e9772
commit
c97ee862a5
|
@ -625,7 +625,12 @@ class Protocol:
|
|||
with objects_cache_lock:
|
||||
cached = objects_cache.get(id)
|
||||
if cached:
|
||||
return cached
|
||||
# make a copy so that if the client modifies this entity in
|
||||
# memory, those modifications aren't applied to the cache
|
||||
# until they explicitly put() the modified entity.
|
||||
return Object(id=cached.key.id(), **cached.to_dict(
|
||||
# computed properties
|
||||
exclude=['as1', 'expire', 'object_ids', 'type']))
|
||||
|
||||
obj = orig_as1 = None
|
||||
if local:
|
||||
|
|
|
@ -11,6 +11,7 @@ from .testutil import Fake, TestCase
|
|||
|
||||
from models import AtpNode, Follower, Object, OBJECT_EXPIRE_AGE
|
||||
import protocol
|
||||
from protocol import Protocol
|
||||
from web import Web
|
||||
|
||||
from .test_activitypub import ACTOR
|
||||
|
|
|
@ -196,11 +196,16 @@ class ProtocolTest(TestCase):
|
|||
self.assertEqual([], Fake.fetched)
|
||||
|
||||
def test_load_cached(self):
|
||||
obj = Object(our_as1={'x': 'y'})
|
||||
obj = Object(id='foo', our_as1={'x': 'y'})
|
||||
protocol.objects_cache['foo'] = obj
|
||||
loaded = Fake.load('foo')
|
||||
self.assert_entities_equal(obj, loaded)
|
||||
|
||||
# check that it's a separate copy of the entity in the cache
|
||||
# https://github.com/snarfed/bridgy-fed/issues/558#issuecomment-1603203927
|
||||
loaded.our_as1 = {'a': 'b'}
|
||||
self.assertEqual({'x': 'y'}, Protocol.load('foo').our_as1)
|
||||
|
||||
def test_load_remote_true_existing_empty(self):
|
||||
Fake.objects['foo'] = {'x': 'y'}
|
||||
Object(id='foo').put()
|
||||
|
|
Ładowanie…
Reference in New Issue