def deleteMultiple(cls, ids):
     from lp.bugs.model.structuralsubscription import StructuralSubscription
     store = IStore(BugSubscriptionFilter)
     structsub_ids = list(
         store.find(
             BugSubscriptionFilter.structural_subscription_id,
             BugSubscriptionFilter.id.is_in(ids)))
     kinds = [
         BugSubscriptionFilterImportance, BugSubscriptionFilterStatus,
         BugSubscriptionFilterTag, BugSubscriptionFilterInformationType]
     for kind in kinds:
         store.find(kind, kind.filter_id.is_in(ids)).remove()
     store.find(
         BugSubscriptionFilter,
         BugSubscriptionFilter.id.is_in(ids)).remove()
     # Now delete any structural subscriptions that have no filters.
     # Take out a SHARE lock on the filters that we use as evidence
     # for keeping structsubs, to ensure that they haven't been
     # deleted under us.
     filter_expr = Select(
         1, tables=[BugSubscriptionFilter],
         where=(
             BugSubscriptionFilter.structural_subscription_id
                 == StructuralSubscription.id))
     locked_filter_expr = SQL(
         convert_storm_clause_to_string(filter_expr) + ' FOR SHARE')
     store.find(
         StructuralSubscription,
         StructuralSubscription.id.is_in(structsub_ids),
         Not(Exists(locked_filter_expr))).remove()
Пример #2
0
 def deleteMultiple(cls, ids):
     from lp.bugs.model.structuralsubscription import StructuralSubscription
     store = IStore(BugSubscriptionFilter)
     structsub_ids = list(
         store.find(BugSubscriptionFilter.structural_subscription_id,
                    BugSubscriptionFilter.id.is_in(ids)))
     kinds = [
         BugSubscriptionFilterImportance, BugSubscriptionFilterStatus,
         BugSubscriptionFilterTag, BugSubscriptionFilterInformationType
     ]
     for kind in kinds:
         store.find(kind, kind.filter_id.is_in(ids)).remove()
     store.find(BugSubscriptionFilter,
                BugSubscriptionFilter.id.is_in(ids)).remove()
     # Now delete any structural subscriptions that have no filters.
     # Take out a SHARE lock on the filters that we use as evidence
     # for keeping structsubs, to ensure that they haven't been
     # deleted under us.
     filter_expr = Select(
         1,
         tables=[BugSubscriptionFilter],
         where=(BugSubscriptionFilter.structural_subscription_id ==
                StructuralSubscription.id))
     locked_filter_expr = SQL(
         convert_storm_clause_to_string(filter_expr) + ' FOR SHARE')
     store.find(StructuralSubscription,
                StructuralSubscription.id.is_in(structsub_ids),
                Not(Exists(locked_filter_expr))).remove()
Пример #3
0
def recursive_dependent_query(user):
    from lp.blueprints.model.specificationsearch import (
        get_specification_privacy_filter)
    return """
        RECURSIVE dependencies(id) AS (
            SELECT ?
        UNION
            SELECT sd.dependency
            FROM dependencies d, specificationdependency sd
            JOIN specification ON sd.dependency = specification.id
            WHERE sd.specification = d.id AND (%s))""" % (
        convert_storm_clause_to_string(
            *get_specification_privacy_filter(user)))
Пример #4
0
def recursive_dependent_query(user):
    from lp.blueprints.model.specificationsearch import (
        get_specification_privacy_filter)
    return """
        RECURSIVE dependencies(id) AS (
            SELECT ?
        UNION
            SELECT sd.dependency
            FROM dependencies d, specificationdependency sd
            JOIN specification ON sd.dependency = specification.id
            WHERE sd.specification = d.id AND (%s))""" % (
                convert_storm_clause_to_string(
                    *get_specification_privacy_filter(user)))
Пример #5
0
 def rough_length(self):
     """See `IRangeFactory."""
     from lp.services.librarian.model import LibraryFileAlias
     # get_select_expr() requires at least one column as a parameter.
     # getorderBy() already knows about columns that can appear
     # in the result set, so let's use them. Moreover, for SELECT
     # DISTINCT queries, each column used for sorting must appear
     # in the result.
     if self.empty_resultset:
         return 0
     columns = [plain_expression(column) for column in self.getOrderBy()]
     select = removeSecurityProxy(
         self.plain_resultset).get_select_expr(*columns)
     explain = 'EXPLAIN ' + convert_storm_clause_to_string(select)
     result = ISlaveStore(LibraryFileAlias).execute(explain)
     _rows_re = re.compile("rows=(\d+)\swidth=")
     first_line = result.get_one()[0]
     match = _rows_re.search(first_line)
     if match is None:
         raise RuntimeError("Unexpected EXPLAIN output %s" %
                            repr(first_line))
     return int(match.group(1))
Пример #6
0
 def rough_length(self):
     """See `IRangeFactory."""
     from lp.services.librarian.model import LibraryFileAlias
     # get_select_expr() requires at least one column as a parameter.
     # getorderBy() already knows about columns that can appear
     # in the result set, so let's use them. Moreover, for SELECT
     # DISTINCT queries, each column used for sorting must appear
     # in the result.
     if self.empty_resultset:
         return 0
     columns = [plain_expression(column) for column in self.getOrderBy()]
     select = removeSecurityProxy(self.plain_resultset).get_select_expr(
         *columns)
     explain = 'EXPLAIN ' + convert_storm_clause_to_string(select)
     result = ISlaveStore(LibraryFileAlias).execute(explain)
     _rows_re = re.compile("rows=(\d+)\swidth=")
     first_line = result.get_one()[0]
     match = _rows_re.search(first_line)
     if match is None:
         raise RuntimeError(
             "Unexpected EXPLAIN output %s" % repr(first_line))
     return int(match.group(1))
Пример #7
0
 def reap(archive, container=None):
     """See `IArchiveFileSet`."""
     # XXX cjwatson 2016-03-30 bug=322972: Requires manual SQL due to
     # lack of support for DELETE FROM ... USING ... in Storm.
     clauses = [
         ArchiveFile.archive == archive,
         ArchiveFile.scheduled_deletion_date < _now(),
         ArchiveFile.library_file_id == LibraryFileAlias.id,
         LibraryFileAlias.contentID == LibraryFileContent.id,
     ]
     if container is not None:
         clauses.append(ArchiveFile.container == container)
     where = convert_storm_clause_to_string(And(*clauses))
     return list(
         IMasterStore(ArchiveFile).execute("""
         DELETE FROM ArchiveFile
         USING LibraryFileAlias, LibraryFileContent
         WHERE """ + where + """
         RETURNING
             ArchiveFile.container,
             ArchiveFile.path,
             LibraryFileContent.sha256
         """))