How do you ‘do something’ to every element in a list except that one index? (C# Beginners Level Question)

I created a list of 40 buttons, each of these buttons have an ‘int counter’ that counts up incrementally to 5 whenever pressed.

If I hit button 1, the other button’s counter will reset and become 0, but the button I hit can now increase to 2, 3, 4, 5.

How would you loop the list in a way that doesn’t also reset the button being pressed?

Button itself is a class, and I have a ButtonManager that contains List< Button > Buttons

javascript – Problema con sesiones en un INDEX PHP

Tengo un login donde ingreso mis credenciales y me redirecciona al dashboard en un index.php que dejare el codigo a continuación. Pero antes, mi problema en particular es que cuando recargo la pagina desde la barra de busqueda, la sesion se cierra y me envia denuevo al login en vez de traerme el dashboard denuevo.

Algo me hace sospechar que la sesion se destruye.

<?php
include_once 'includes/user.php';
include_once 'includes/user_session.php';

$errorLogin = "";

if(isset($_SESSION('user'))){
    $user->setUser($userSession->getCurrentUser());
    include_once 'dashboard.php';

}else if(isset($_POST('username')) && isset($_POST('password'))){
    
    $userForm = $_POST('username');
    $passForm = $_POST('password');
    
    $userSession = new UserSession();
    $user = new User();
    if($user->userExists($userForm, $passForm)){
        // Grant access
        $userSession->setCurrentUser($userForm);
        $user->setUser($userForm);
        include_once 'dashboard.php';
    }else{ 
        // Deny Access
        $errorLogin = "Credenciales inválidas";
        include_once 'login.php';
    }
}else{
    $userSession = new UserSession();
    $user = new User();
    include_once 'login.php';
}
?>

Que puedo estar haciendo mal?

postgresql – Are reportedly “bloated” index sizes a problem?

I create a table with 1m records, then I delete those records. (Common with some sort of processing list.)

CREATE TABLE example (id int PRIMARY KEY);
INSERT INTO example SELECT generate_series(1, 1000 * 1000);
DELETE FROM example;
VACUUM example;

The index size remains at the same size as before deletion.

SELECT pg_size_pretty(pg_relation_size(c.oid)) AS size
FROM pg_class c
WHERE oid = 'example_pkey'::regclass;
 size  
-------
 21 MB
(1 row)

Likewise, bloat-detection queries (e.g. ioguix/pgsql-bloat-estimation) identify this index as extremely bloated.

I don’t care about the disk usage itself. Will the performance of the index be affected by its large size? Should I be running REINDEX?

sql server – Why is Index causing bad estimation and execution plan

SELECT ISNULL(SUM(CASE WHEN T4.f_in =12 THEN T4.f_money END),0) - ISNULL(SUM(CASE WHEN T4.f_out=12 THEN T4.f_money END),0) 
 FROM (Credit) M WITH(NOLOCK) INNER JOIN (Transaction) T4 WITH(NOLOCK) ON M.f_accounts=T4.f_accounts
 AND 
 (
    T4.f_time>=M.f_time OR M.f_time IS NULL
 )
  AND T4.f_other IS NULL 
  AND (T4.f_in=12 OR T4.f_out=12)

After adding an index, one of the queries that originally finishes within 1s now takes around 12s. It seems that the index is now seeked by the query with bad estimation of only 1 row to be read. No other indexes are present in both Credit and Transaction tables.

CREATE NONCLUSTERED INDEX IX_Credit_f_time ON Credit (f_time) INCLUDE (f_accounts,f_credit)

Above is the index added to the table.

enter image description here

Plan without index, takes 1s
enter image description here

Plan with the index, takes 12s. The highlighted parts are number of rows read, estimated number of rows and estimated number of rows to be read respectively.

Statistics are updated with fullscan but results are still the same.

enter image description hereenter image description here
From my understanding the f_time column is pretty concentrated, hash joining the table once would be much more efficient than seeking multiple times.

Full Execution Plan: https://www.brentozar.com/pastetheplan/?id=rJjwvXBA_

magento2.3 – Magento2: How can you check/set which Elasticsearch index is currently being used

We have a large catalog (400k products) that takes a day or two to reindex.

Occasionally I’ve had something go wrong with the indexing process and then nothing is searchable (code errors). I don’t want the site down for days if this happens, so I’d like to clone the current index, then start the Magento reindexing, and if something goes haywire, restore the backup index.

I can’t find how to see/overwrite which version of the index is currently being used.

teradata – clustered index – Database Administrators Stack Exchange

Does it matters which field I specify first in the index?

would

CREATE SET TABLE my_table
(   
        validity_date DATE
    ,   branch_id SMALLINT 
    ,   account_class_id BYTEINT
    ,   catalog_id INTEGER
    ,   No_events FLOAT
)
PRIMARY INDEX (validity_date, branch_id);

be treated by the server same as

CREATE SET TABLE my_table
(   
        validity_date DATE
    ,   branch_id SMALLINT 
    ,   account_class_id BYTEINT
    ,   catalog_id INTEGER
    ,   No_events FLOAT
)
PRIMARY INDEX (branch_id, validity_date);

Forum Index Redirect Auction #22 | Forum Promotion


Forum Index Redirect Auction
Auction closes on 07/25/21 at 12 AM EST.
Contest Status:
Open


In this auction, you are bidding FP$ for the opportunity to have your website link advertised on Forum Promotion’s forum index in the “Forum Redirect Auction” advertising space for one month after the end of this raffle. The member that bids the most FP$ before the end of the auction will win.

Please review the following rules prior to bidding.

Bidding Rules:

  • Must have at least 10 posts on FP – Only members who have 10 or more posts are permitted to bid.
  • Must have equivalent FP$ to match your bid – Failure to have the equivalent amount of FP$ to match your bid will result in your bid being voided and a note added to your account.
  • Bids must be increments of 10 FP$ or higher – Any bids less than 10 FP$ from the previous bid shall be ignored.
  • End of Auction – Only bids before the end of the current week’s closing time will count. Those who bid after the closing time of the auction will be voided.

How to bid:
Simply reply to this thread below with your bid!

sql server – What is the point of adding an unrelated index field to a heap?

I have a heap with a unique non-clustered index on field1+field2.

I have been advised to add a new identity primary key so as to create a clustered index for the table.

But if this index is never referred to in my code, what is the point of adding it?

How can I index arbitrarily related entity data in a Search API index the same as if it were an entity reference?

This is possible with custom search_api processors.

First, I created an abstract class to use as a base for the shared functionality. I.e. a method to index arbitrary entity data with a piece of content.

namespace Drupalmy_modulePluginsearch_apiprocessor;

use DrupalCoreEntityContentEntityInterface;
use Drupalsearch_apiDatasourceDatasourceInterface;
use Drupalsearch_apiItemItemInterface;
use Drupalsearch_apiProcessorEntityProcessorProperty;
use Drupalsearch_apiProcessorProcessorPluginBase;
use Drupalsearch_apiUtilityUtility;

/**
 * Base plugin class for indexing arbitrarily related entity data.
 *
 * This can be helpful to index properties of entities referencing an entity or
 * entities related in some other arbitrary way.
 *
 * @package Drupalmy_modulePluginsearch_apiprocessor
 */
abstract class RelatedEntityBase extends ProcessorPluginBase {

  /**
   * {@inheritdoc}
   */
  public function getPropertyDefinitions(DatasourceInterface $datasource = NULL) {
    $plugin_definition = $this->getPluginDefinition();
    $properties = ();

    if (!$datasource || $datasource->getEntityTypeId() !== $this->getIndexedEntityTypeId()) {
      return $properties;
    }

    $definition = (
      'label' => $plugin_definition('label'),
      'description' => $plugin_definition('description'),
      'type' => 'entity:' . $this->getRelatedEntityTypeId(),
      'processor_id' => $this->getPluginId(),
      'is_list' => TRUE,
    );
    $property = new EntityProcessorProperty($definition);
    $property->setEntityTypeId($this->getRelatedEntityTypeId());
    $properties($this->getPluginId()) = $property;

    return $properties;
  }

  /**
   * {@inheritdoc}
   */
  public function addFieldValues(ItemInterface $item) {
    /** @var DrupalCoreEntityContentEntityInterface $entity */
    $entity = $item->getOriginalObject()->getValue();

    $to_extract = ();
    foreach ($item->getFields() as $field) {
      $datasource = $field->getDatasource();
      $property_path = $field->getPropertyPath();
      ($direct, $nested) = Utility::splitPropertyPath($property_path, FALSE);
      if ($datasource && $datasource->getEntityTypeId() === $entity->getEntityTypeId() && $direct === $this->getPluginId()) {
        $to_extract($nested)() = $field;
      }
    }

    foreach ($this->getRelatedEntities($entity) as $relation) {
      $this->getFieldsHelper()
        ->extractFields($relation->getTypedData(), $to_extract, $item->getLanguage());
    }
  }

  /**
   * Get an array of related entities.
   *
   * This should return an array of fully loaded entities that relate to the
   * $entity being indexed.
   *
   * @param DrupalCoreEntityContentEntityInterface $entity
   *   The entity being indexed.
   *
   * @return array
   *   An array of entities related to $entity.
   */
  abstract protected function getRelatedEntities(ContentEntityInterface $entity): array;

  /**
   * Get the entity type id of the entity being indexed.
   *
   * This is the entity type of the $entity passed to
   * $this->getRelatedEntities().
   *
   * @return string
   *   An entity type id string, e.g. 'node', 'media', or 'taxonomy_term'.
   */
  abstract protected function getIndexedEntityTypeId(): string;

  /**
   * Get the entity type id of the related entities.
   *
   * This is the entity type of the items returned from
   * $this->getRelatedEntities().
   *
   * @return string
   *   An entity type id string, e.g. 'node', 'media', or 'taxonomy_term'.
   */
  abstract protected function getRelatedEntityTypeId(): string;

}

Next, I created plugin classes that extended my abstract class for each case (Collection’s Authors, Article’s Collections, Author’s Collections). For example, to index data from an Article’s Collections as part of the Article’s indexed data:

namespace Drupalmy_modulePluginsearch_apiprocessor;

use DrupalCoreEntityContentEntityInterface;
use Drupalmy_modulePluginsearch_apiprocessorRelatedEntityBase;

/**
 * Index properties from Collections referencing an Article.
 *
 * @SearchApiProcessor(
 *   id = "my_module_article_collections",
 *   label = @Translation("Article's Collections"),
 *   description = @Translation("Index properties from Collections referencing this Article."),
 *   stages = {
 *     "add_properties" = 0,
 *   },
 * )
 */
class ArticleCollections extends RelatedEntityBase {

  /**
   * {@inheritdoc}
   */
  protected function getRelatedEntities(ContentEntityInterface $entity): array {
    return my_function_to_get_article_collections($entity)
  }

  /**
   * {@inheritdoc}
   */
  protected function getIndexedEntityTypeId(): string {
    return 'node';
  }

  /**
   * {@inheritdoc}
   */
  protected function getRelatedEntityTypeId(): string {
    return 'node';
  }

}

This allowed me to index data from a Collection as part of an Article’s data, for example the Article’s Collection Ids (i.e. the Ids of Collections referencing the Article). I can index any field from the Collection – by selecting the field I want in the UI – the same as if the Article had an entity reference field referencing the Collection. (Note: before you can index any fields with the custom processor, you must first enable it on the Processor tab for your index.)

This all worked great, however, my indexed data did not stay synced with reality. For example, if I added a new Article to a Collection, the indexed data for that new Article would not get updated with information for the new Collection. I.e. the Article was not getting re-indexed if a Collection referencing it was updated. I resolved this with a hook_ENTITY_TYPE_update() implementation that marks dependent Articles to be re-indexed when a Collection is saved.

use DrupalnodeNodeInterface;

/*
 * Implements hook_ENTITY_TYPE_update().
 */
function my_module_node_update(NodeInterface $node) {
  if ($node->bundle() == 'collection') {
    $articles = ();

    // Gather all Articles that this Collection references.
    $articles = my_function_to_get_collection_articles($node);
    // Also gather any Articles that were referenced before this save, but are
    // no longer referenced.
    $original_node = isset($node->original) ? $node->original : NULL;
    if ($original_node instanceof NodeInterface) {
      $articles += my_function_to_get_collection_articles($original_node);
    }

    // Mark the articles to be re-indexed.
    foreach ($articles as $article) {
      /** @var Drupalsearch_apiPluginsearch_apidatasourceContentEntityTrackingManager $tracking_manager */
      $search_api_tracking_manager = Drupal::service('search_api.entity_datasource.tracking_manager');

      $indexes = $search_api_tracking_manager->getIndexesForEntity($article);
      if (!empty($indexes)) {
        $item_ids = ();
        foreach ($article->getTranslationLanguages() as $langcode => $language) {
          $item_ids() = $article->id() . ':' . $langcode;
        }
        foreach ($indexes as $index) {
          $index->trackItemsUpdated('entity:node', $item_ids);
        }
      }
    }
  }
}

After all of this, I can safely index data from arbitrarily related entities.

Why does Bitcoin Core support a transaction index but not an address index?

Bitcoin Core has the CLI option -txindex to maintain a full transaction index for RPC calls. That sounds useful for some use cases, like for a blockchain explorer. It seems perfectly logical then that there should also be an option to enable an address index, which would allow looking up address balances and transaction histories, but there isn’t one. Why is that? And why exactly was -txindex included in the first place?