53 $dbr = $this->getReplicaDb();
55 $depsBlobByEntity = $this->fetchDependencyBlobs( $entities, $dbr );
57 $storedPathsByEntity = [];
58 foreach ( $depsBlobByEntity as $entity => $depsBlob ) {
59 $storedPathsByEntity[$entity] = json_decode( $depsBlob,
true );
63 foreach ( $entities as $entity ) {
64 $paths = $storedPathsByEntity[$entity] ?? [];
71 public function storeMulti( $type, array $dataByEntity, $ttl ) {
75 if ( !$dataByEntity ) {
79 $dbw = $this->getPrimaryDb();
80 $depsBlobByEntity = $this->fetchDependencyBlobs( array_keys( $dataByEntity ), $dbw );
83 foreach ( $dataByEntity as $entity => $data ) {
84 [ $module, $variant ] = $this->getEntityNameComponents( $entity );
85 if ( !is_array( $data[self::KEY_PATHS] ) ) {
86 throw new InvalidArgumentException(
"Invalid entry for '$entity'" );
90 $paths = array_values( array_unique( $data[self::KEY_PATHS] ) );
91 sort( $paths, SORT_STRING );
92 $blob = json_encode( $paths, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
94 $existingBlob = $depsBlobByEntity[$entity] ??
null;
95 if ( $blob !== $existingBlob ) {
97 'md_module' => $module,
98 'md_skin' => $variant,
106 foreach ( $rows as $row ) {
107 $dbw->newInsertQueryBuilder()
108 ->insertInto(
'module_deps' )
110 ->onDuplicateKeyUpdate()
111 ->uniqueIndexFields( [
'md_module',
'md_skin' ] )
112 ->set( [
'md_deps' => $row[
'md_deps'] ] )
113 ->caller( __METHOD__ )->execute();
117 public function remove( $type, $entities ) {
125 $dbw = $this->getPrimaryDb();
126 $disjunctionConds = [];
127 foreach ( (array)$entities as $entity ) {
128 [ $module, $variant ] = $this->getEntityNameComponents( $entity );
129 $disjunctionConds[] = $dbw
130 ->expr(
'md_skin',
'=', $variant )
131 ->and(
'md_module',
'=', $module );
134 if ( $disjunctionConds ) {
135 $dbw->newDeleteQueryBuilder()
136 ->deleteFrom(
'module_deps' )
137 ->where( $dbw->orExpr( $disjunctionConds ) )
138 ->caller( __METHOD__ )->execute();