~rashi007/mailman/mailman

« back to all changes in this revision

Viewing changes to src/mailman/model/uid.py

  • Committer: Barry Warsaw
  • Date: 2015-02-13 08:13:06 UTC
  • Revision ID: barry@list.org-20150213081306-1b567rjfxqw45ti6
 * A new API is provided to support non-production testing infrastructures,
   allowing a client to cull all orphaned UIDs via ``DELETE`` on
   ``<api>/reserved/uids/orphans``.  Note that *no guarantees* of API
   stability will ever be made for resources under ``reserved``.
   (LP: #1420083)

Also:

- Allow @dbconnection methods to be @staticmethods taking only one argument,
  the store to perform the query on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
        if existing.count() != 0:
75
75
            raise ValueError(uid)
76
76
        return UID(uid)
 
77
 
 
78
    @staticmethod
 
79
    @dbconnection
 
80
    def get_total_uid_count(store):
 
81
        return store.query(UID).count()
 
82
 
 
83
    @staticmethod
 
84
    @dbconnection
 
85
    def cull_orphans(store):
 
86
        # Avoid circular imports.
 
87
        from mailman.model.user import User
 
88
        # Delete all uids in this table that are not associated with user
 
89
        # rows.
 
90
        results = store.query(UID).filter(
 
91
            ~UID.uid.in_(store.query(User._user_id)))
 
92
        for uid in results.all():
 
93
            store.delete(uid)