3737use  OCP \Files \IAppData ;
3838use  OCP \Files \NotFoundException ;
3939use  OCP \Http \Client \IClientService ;
40+ use  OCP \ICache ;
41+ use  OCP \ICacheFactory ;
4042use  OCP \IConfig ;
4143use  OCP \ILogger ;
4244
@@ -61,6 +63,8 @@ abstract class Fetcher {
6163	protected  $ version
6264	/** @var string */ 
6365	protected  $ channel
66+ 	/** @var ICache */ 
67+ 	private  $ cache
6468
6569	/** 
6670	 * @param Factory $appDataFactory 
@@ -73,12 +77,15 @@ public function __construct(Factory $appDataFactory,
7377								IClientService $ clientService
7478								ITimeFactory $ timeFactory
7579								IConfig $ config
76- 								ILogger $ logger
80+ 								ILogger $ logger
81+ 								ICacheFactory $ cacheFactory
82+ 	) {
7783		$ this appData  = $ appDataFactoryget ('appstore ' );
7884		$ this clientService  = $ clientService
7985		$ this timeFactory  = $ timeFactory
8086		$ this config  = $ config
8187		$ this logger  = $ logger
88+ 		$ this cache  = $ cacheFactorycreateDistributed ('appstore-fetcher ' );
8289	}
8390
8491	/** 
@@ -91,6 +98,9 @@ public function __construct(Factory $appDataFactory,
9198	 */ 
9299	protected  function  fetch ($ ETag$ content
93100		$ appstoreenabled$ this config ->getSystemValue ('appstoreenabled ' , true );
101+ 		if  ((bool )$ this cache ->get ('lastFetchFailure ' )) {
102+ 			return  [];
103+ 		}
94104
95105		if  (!$ appstoreenabled
96106			return  [];
@@ -107,7 +117,13 @@ protected function fetch($ETag, $content) {
107117		}
108118
109119		$ client$ this clientService ->newClient ();
110- 		$ response$ clientget ($ this getEndpoint (), $ options
120+ 		try  {
121+ 			$ response$ clientget ($ this getEndpoint (), $ options
122+ 		} catch  (ConnectException $ e
123+ 			// Only retry app store fetching once every 5 minutes when failing 
124+ 			$ this cache ->set ('lastFetchFailure ' , true , 300 );
125+ 			throw  $ e
126+ 		}
111127
112128		$ responseJson
113129		if  ($ responsegetStatusCode () === Http::STATUS_NOT_MODIFIED ) {
@@ -175,6 +191,9 @@ public function get($allowUnstable = false) {
175191		// Refresh the file content 
176192		try  {
177193			$ responseJson$ this fetch ($ ETag$ content$ allowUnstable
194+ 			if  (empty ($ responseJson'data ' ])) {
195+ 				return  [];
196+ 			}
178197			// Don't store the apps request file 
179198			if  ($ allowUnstable
180199				return  $ responseJson'data ' ];
0 commit comments