Skip to content

Commit

Permalink
#23982 speeding up vanity url loading
Browse files Browse the repository at this point in the history
  • Loading branch information
wezell committed Feb 2, 2023
1 parent a644844 commit 4daa266
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
Expand Up @@ -61,6 +61,7 @@ public class VanityUrlAPIImpl implements VanityUrlAPI {
" SELECT cvi.live_inode "
+ " FROM identifier, contentlet_version_info cvi "
+ " where "
+ " cvi.live_inode is not null and "
+ " identifier.id = cvi.identifier and "
+ " identifier.host_inode = ? and "
+ " cvi.lang = ? and "
Expand Down
Expand Up @@ -252,17 +252,17 @@ public void loadResult(Connection conn) throws DotDataException {
public boolean executeStatement(String sql) throws SQLException {
Connection conn = DbConnectionFactory.getConnection();
Statement stmt = conn.createStatement();
Logger.info(this, "Executing " + sql);
Logger.debug(this, "Executing " + sql);
boolean ret = stmt.execute(sql);
stmt.close();
return ret;
}

public boolean executeStatement(String sql, Connection con) throws SQLException {
Statement stmt = con.createStatement();
Logger.info(this, "Executing " + sql);
Logger.debug(this, "Executing " + sql);
boolean ret = stmt.execute(sql);
Logger.info(this, "Finished Executing " + sql);
Logger.debug(this, "Finished Executing " + sql);
stmt.close();
return ret;
}
Expand Down
@@ -1,19 +1,38 @@
package com.dotmarketing.startup.runonce;

import com.dotmarketing.common.db.DotConnect;
import com.dotmarketing.db.DbConnectionFactory;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotRuntimeException;
import com.dotmarketing.startup.StartupTask;
import com.dotmarketing.util.Logger;
import java.sql.Connection;
import java.sql.SQLException;

public class Task210719CleanUpTitleField implements StartupTask {
@Override
public boolean forceRun() {
return true;
}

@Override

public void executeUpgrade() throws DotDataException, DotRuntimeException {

if(DbConnectionFactory.isPostgres()) {
executePgUpgrade();
}

if(DbConnectionFactory.isMsSql()) {
executeSQLServerUpgrade();
}




}


public void executeSQLServerUpgrade() throws DotDataException, DotRuntimeException {

try {
new DotConnect()
Expand All @@ -22,4 +41,38 @@ public void executeUpgrade() throws DotDataException, DotRuntimeException {
throw new DotRuntimeException(exception);
}
}





public void executePgUpgrade() throws DotDataException, DotRuntimeException {




int rowsAffecrted=0;

try (Connection conn = DbConnectionFactory.getDataSource().getConnection()){

int remaining = (int) new DotConnect().setSQL("select inode from contentlet where title is not null limit 1").loadObjectResults(conn).size();
while(remaining>0) {

new DotConnect()
.executeStatement("update contentlet set title=null where contentlet.inode in (select inode from contentlet where title is not null limit 500)", conn);
rowsAffecrted+=500;
Logger.info(getClass(), "Task210719CleanUpTitleField Updated: "+ rowsAffecrted );
remaining = (int) new DotConnect().setSQL("select inode from contentlet where title is not null limit 1").loadObjectResults(conn).size();
}



} catch (SQLException exception) {
throw new DotRuntimeException(exception);
}
}




}

0 comments on commit 4daa266

Please sign in to comment.