54 $dbr = $this->getReplicaDb();
56 $depsBlobByEntity = $this->fetchDependencyBlobs( $entities, $dbr );
58 $storedPathsByEntity = [];
59 foreach ( $depsBlobByEntity as $entity => $depsBlob ) {
60 $storedPathsByEntity[$entity] = json_decode( $depsBlob,
true );
64 foreach ( $entities as $entity ) {
65 $paths = $storedPathsByEntity[$entity] ?? [];
72 public function storeMulti( $type, array $dataByEntity, $ttl ) {
76 if ( !$dataByEntity ) {
80 $dbw = $this->getPrimaryDb();
81 $depsBlobByEntity = $this->fetchDependencyBlobs( array_keys( $dataByEntity ), $dbw );
84 foreach ( $dataByEntity as $entity => $data ) {
85 [ $module, $variant ] = $this->getEntityNameComponents( $entity );
86 if ( !is_array( $data[self::KEY_PATHS] ) ) {
87 throw new InvalidArgumentException(
"Invalid entry for '$entity'" );
91 $paths = array_values( array_unique( $data[self::KEY_PATHS] ) );
92 sort( $paths, SORT_STRING );
93 $blob = json_encode( $paths, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
95 $existingBlob = $depsBlobByEntity[$entity] ??
null;
96 if ( $blob !== $existingBlob ) {
98 'md_module' => $module,
99 'md_skin' => $variant,
107 foreach ( $rows as $row ) {
108 $dbw->newInsertQueryBuilder()
109 ->insertInto(
'module_deps' )
111 ->onDuplicateKeyUpdate()
112 ->uniqueIndexFields( [
'md_module',
'md_skin' ] )
113 ->set( [
'md_deps' => $row[
'md_deps'] ] )
114 ->caller( __METHOD__ )->execute();
118 public function remove( $type, $entities ) {
126 $dbw = $this->getPrimaryDb();
127 $disjunctionConds = [];
128 foreach ( (array)$entities as $entity ) {
129 [ $module, $variant ] = $this->getEntityNameComponents( $entity );
130 $disjunctionConds[] = $dbw
131 ->expr(
'md_skin',
'=', $variant )
132 ->and(
'md_module',
'=', $module );
135 if ( $disjunctionConds ) {
136 $dbw->newDeleteQueryBuilder()
137 ->deleteFrom(
'module_deps' )
139 ->caller( __METHOD__ )->execute();