Example #1
0
        public async Task <AuxiliaryFileResult <PopularityTransferData> > ReadLatestIndexedAsync(
            IAccessCondition accessCondition,
            StringCache stringCache)
        {
            var stopwatch     = Stopwatch.StartNew();
            var blobName      = GetLatestIndexedBlobName();
            var blobReference = Container.GetBlobReference(blobName);

            _logger.LogInformation("Reading the latest indexed popularity transfers from {BlobName}.", blobName);

            bool modified;
            var  data = new PopularityTransferData();
            AuxiliaryFileMetadata metadata;

            try
            {
                using (var stream = await blobReference.OpenReadAsync(accessCondition))
                {
                    ReadStream(stream, (from, to) => data.AddTransfer(stringCache.Dedupe(from), stringCache.Dedupe(to)));
                    modified = true;
                    metadata = new AuxiliaryFileMetadata(
                        lastModified: new DateTimeOffset(blobReference.LastModifiedUtc, TimeSpan.Zero),
                        loadDuration: stopwatch.Elapsed,
                        fileSize: blobReference.Properties.Length,
                        etag: blobReference.ETag);
                }
            }
            catch (StorageException ex) when(ex.RequestInformation.HttpStatusCode == (int)HttpStatusCode.NotModified)
            {
                _logger.LogInformation("The blob {BlobName} has not changed.", blobName);
                modified = false;
                data     = null;
                metadata = null;
            }

            stopwatch.Stop();
            _telemetryService.TrackReadLatestIndexedPopularityTransfers(data?.Count, modified, stopwatch.Elapsed);

            return(new AuxiliaryFileResult <PopularityTransferData>(
                       modified,
                       data,
                       metadata));
        }