<commit_before>using System.Collections.Generic;
using System.Linq;
using Umbraco.Cms.Infrastructure.Persistence.Dtos;

namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_0_0
{
    public class ExternalLoginTableIndexes : MigrationBase
    {
        public ExternalLoginTableIndexes(IMigrationContext context)
            : base(context)
        {
        }

        /// <summary>
        /// Adds new indexes to the External Login table
        /// </summary>
        protected override void Migrate()
        {
            // Before adding these indexes we need to remove duplicate data.
            // Get all logins by latest
            var logins = Database.Fetch<ExternalLoginDto>()
                .OrderByDescending(x => x.CreateDate)
                .ToList();

            var toDelete = new List<int>();
            // used to track duplicates so they can be removed
            var keys = new HashSet<(string, string)>();
            foreach(ExternalLoginDto login in logins)
            {
                if (!keys.Add((login.ProviderKey, login.LoginProvider)))
                {
                    // if it already exists we need to remove this one
                    toDelete.Add(login.Id);
                }
            }
            if (toDelete.Count > 0)
            {
                Database.DeleteMany<ExternalLoginDto>().Where(x => toDelete.Contains(x.Id)).Execute();
            }   

            var indexName1 = "IX_" + ExternalLoginDto.TableName + "_LoginProvider";

            if (!IndexExists(indexName1))
            {
                Create
                     .Index(indexName1)
                     .OnTable(ExternalLoginDto.TableName)
                     .OnColumn("loginProvider")
                     .Ascending()
                     .WithOptions()
                     .Unique()
                     .WithOptions()
                     .NonClustered()
                     .Do();
            }

            var indexName2 = "IX_" + ExternalLoginDto.TableName + "_ProviderKey";

            if (!IndexExists(indexName2))
            {
                Create
                     .Index(indexName2)<commit_msg>add userId to IX_ExternalLogin_LoginProvider<commit_after>using System.Collections.Generic;
using System.Linq;
using Umbraco.Cms.Infrastructure.Persistence.Dtos;

namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_0_0
{
    public class ExternalLoginTableIndexes : MigrationBase
    {
        public ExternalLoginTableIndexes(IMigrationContext context)
            : base(context)
        {
        }

        /// <summary>
        /// Adds new indexes to the External Login table
        /// </summary>
        protected override void Migrate()
        {
            // Before adding these indexes we need to remove duplicate data.
            // Get all logins by latest
            var logins = Database.Fetch<ExternalLoginDto>()
                .OrderByDescending(x => x.CreateDate)
                .ToList();

            var toDelete = new List<int>();
            // used to track duplicates so they can be removed
            var keys = new HashSet<(string, string)>();
            foreach(ExternalLoginDto login in logins)
            {
                if (!keys.Add((login.ProviderKey, login.LoginProvider)))
                {
                    // if it already exists we need to remove this one
                    toDelete.Add(login.Id);
                }
            }
            if (toDelete.Count > 0)
            {
                Database.DeleteMany<ExternalLoginDto>().Where(x => toDelete.Contains(x.Id)).Execute();
            }   

            var indexName1 = "IX_" + ExternalLoginDto.TableName + "_LoginProvider";

            if (!IndexExists(indexName1))
            {
                Create
                     .Index(indexName1)
                     .OnTable(ExternalLoginDto.TableName)
                     .OnColumn("loginProvider").Ascending()
                     .OnColumn("userId").Ascending()
                     .WithOptions()
                     .Unique()
                     .WithOptions()
                     .NonClustered()
                     .Do();
            }

            var indexName2 = "IX_" + ExternalLoginDto.TableName + "_ProviderKey";

            if (!IndexExists(indexName2))
            {
                Create
                     .Index(indexName2)
{'fraction_non_alphanumeric': 0.09124087591240876, 'fraction_numerical': 0.004562043795620438, 'mean_word_length': 1.398796498905908, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1467655', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1052, 'n_words': 238}