Hangfire now dies gracefully when using CTRL+C rather than Stop button in Rider. Implemented one stream method for testing. Regenerated a few migrations due to oversight in index not taking account of library.
This commit is contained in:
parent
126fb57f4d
commit
9035b6cc4e
17 changed files with 156 additions and 41 deletions
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
@ -112,5 +113,7 @@ namespace API.Data
|
|||
.Include(l => l.Folders)
|
||||
.ProjectTo<LibraryDto>(_mapper.ConfigurationProvider).ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace API.Data.Migrations
|
||||
{
|
||||
public partial class SearchIndex : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Series_Name_NormalizedName_LocalizedName",
|
||||
table: "Series",
|
||||
columns: new[] { "Name", "NormalizedName", "LocalizedName" },
|
||||
unique: true);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Series_Name_NormalizedName_LocalizedName",
|
||||
table: "Series");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,8 +9,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||
namespace API.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(DataContext))]
|
||||
[Migration("20210313001830_SearchIndex")]
|
||||
partial class SearchIndex
|
||||
[Migration("20210315134028_SearchIndexAndProgressDates")]
|
||||
partial class SearchIndexAndProgressDates
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
|
@ -161,6 +161,12 @@ namespace API.Data.Migrations
|
|||
b.Property<int>("ChapterId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("Created")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("LastModified")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("PagesRead")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
|
@ -367,7 +373,7 @@ namespace API.Data.Migrations
|
|||
|
||||
b.HasIndex("LibraryId");
|
||||
|
||||
b.HasIndex("Name", "NormalizedName", "LocalizedName")
|
||||
b.HasIndex("Name", "NormalizedName", "LocalizedName", "LibraryId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Series");
|
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace API.Data.Migrations
|
||||
{
|
||||
public partial class SearchIndexAndProgressDates : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "Created",
|
||||
table: "AppUserProgresses",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
|
||||
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "LastModified",
|
||||
table: "AppUserProgresses",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Series_Name_NormalizedName_LocalizedName_LibraryId",
|
||||
table: "Series",
|
||||
columns: new[] { "Name", "NormalizedName", "LocalizedName", "LibraryId" },
|
||||
unique: true);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Series_Name_NormalizedName_LocalizedName_LibraryId",
|
||||
table: "Series");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Created",
|
||||
table: "AppUserProgresses");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "LastModified",
|
||||
table: "AppUserProgresses");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -159,6 +159,12 @@ namespace API.Data.Migrations
|
|||
b.Property<int>("ChapterId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("Created")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("LastModified")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("PagesRead")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
|
@ -365,7 +371,7 @@ namespace API.Data.Migrations
|
|||
|
||||
b.HasIndex("LibraryId");
|
||||
|
||||
b.HasIndex("Name", "NormalizedName", "LocalizedName")
|
||||
b.HasIndex("Name", "NormalizedName", "LocalizedName", "LibraryId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Series");
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -275,5 +277,54 @@ namespace API.Data
|
|||
v.PagesRead = userProgress.Where(p => p.VolumeId == v.Id).Sum(p => p.PagesRead);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of Series that were added within 2 weeks.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">Library to restrict to, if 0, will apply to all libraries</param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<SeriesDto>> GetRecentlyAdded(int libraryId)
|
||||
{
|
||||
// && (libraryId <= 0 || s.LibraryId == libraryId)
|
||||
var twoWeeksAgo = DateTime.Today.Subtract(TimeSpan.FromDays(14));
|
||||
_logger.LogDebug("2 weeks from today is: {Date}", twoWeeksAgo);
|
||||
return await _context.Series
|
||||
.Where(s => s.Created > twoWeeksAgo)
|
||||
.Take(20)
|
||||
.AsNoTracking()
|
||||
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)
|
||||
.ToListAsync();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public async Task<IEnumerable<SeriesDto>> GetSeriesStream(int userId)
|
||||
{
|
||||
// Testing out In Progress to figure out how to design generalized solution
|
||||
var userProgress = await _context.AppUserProgresses
|
||||
.Where(p => p.AppUserId == userId && p.PagesRead > 0)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
if (!userProgress.Any()) return new SeriesDto[] {};
|
||||
|
||||
var seriesIds = userProgress.Select(p => p.SeriesId).ToList();
|
||||
/*
|
||||
*select P.*, S.Name, S.Pages from AppUserProgresses AS P
|
||||
LEFT join Series as "S" on s.Id = P.SeriesId
|
||||
where AppUserId = 1 AND P.PagesRead > 0 AND P.PagesRead < S.Pages
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
// var series = await _context.Series
|
||||
// .Where(s => seriesIds.Contains(s.Id) && s.Pages) // I need a join
|
||||
|
||||
|
||||
|
||||
|
||||
return new SeriesDto[] {};
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue