Opened 13 years ago

Last modified 12 years ago

#64 closed defect (FIXED)

MediaEntry['uploader'] should reference User, not embed it.

Reported by: Christopher Allan Webber Owned by:
Priority: critical Milestone: 0.0.2
Component: programming Keywords:
Cc: Parent Tickets:

Description (last modified by Christopher Allan Webber)

Currently we embed the User object into the MediaEntry field. Bad,
bad bad! This means all sorts of terrible things, but especially
that we'll be keeping potentially out of date information. We
should be referencing it instead.



Change History (10)

comment:1 by Elrond, 13 years ago

Oh, fun, didn't expect this.

Anyway: Make sure, that the new schema has referential integrity.
(We don't want to delete users that are still referenced from
media, postings, etc).
I hope monogo supports that.

Oh, and we'll most likely get a migration in this area later with
federation, when users from remote sites post comments for example.
(or are allowed to upload media...)



comment:2 by Christopher Allan Webber, 13 years ago

We could use autorefs which would use mostly the same API as we
have now but would probably result in many extra queries than we
would like to make.

In other words, we could do:

::

    from pymongo.dbref import DBRef
    [...]
    class MediaEntry(Document):
        __collection__ = 'media_entries'
    
        structure = {
            'uploader': DBRef,

Which would be faster (one less query when we don't need to
reference the User) but would require an extra query whenever we
pull down a MediaEntry. We could probably add def user() to make
that easier.

Alternately we could turn on autorefs:

`http://namlook.github.com/mongokit/dbref.html <http://namlook.github.com/mongokit/dbref.html>`_

And yeah, we'll probably migrate later. Actually doing a migration
for this doesn't look hard, I just don't want to do it right now
:)



comment:3 by Elrond, 13 years ago

We're pre-alpha. If something breaks, noone should cry. And it can
all be easily fixed currently.
IF the migration looks simple, why not try it?
Major benefit:
- We have an example migration in the code.-
- It's tested, can be documented, etc.

if the migration is harder, it **might** still be an oportunity to
have a "big real world example".

About auto\_refs: To me, this feels a little like magic. I don't
know. The mongo experts should decide.



comment:4 by Christopher Allan Webber, 13 years ago

Compelling points. Okay, we'll try a migration and see how hard it
is.



comment:5 by Christopher Allan Webber, 13 years ago

[https://gitorious.org/\ :sub:`cwebber/mediagoblin/cwebbers-mediagoblin/commits/user\_migration](https://gitorious.org/`\ cwebber/mediagoblin/cwebbers-mediagoblin/commits/user\_migration)

I've made the migration here, it works. The rest of the system not
updated yet to use the migration quite yet.



comment:6 by Christopher Allan Webber, 13 years ago

Oh by the way, to run bulk migrations you'll have to run ./bin/gmg
migrate.



comment:7 by Christopher Allan Webber, 13 years ago

Status: NewClosed
Done, merged, pushed to master.



comment:8 by Elrond, 13 years ago

Milestone: 0.0.2
Looks like this happened for 0.0.2



comment:9 by Will Kahn-Greene, 13 years ago

The original url for this bug was http://bugs.foocorp.net/issues/340 .

comment:10 by Christopher Allan Webber, 12 years ago

Component: programming
Description: modified (diff)
Note: See TracTickets for help on using tickets.